jQuery ajoute et supprime $ (window) .scroll (function ()?

Comment puis-je supprimer puis append le $(window).scroll ? Je dois stocker une variable et la réutiliser après un événement.

 // here i store my var $(window).scroll(function(){ myScroll = $(window).scrollTop() }); $("#itemUnbind").click(function(){ // here i need to remove the listener }); $("#itemBind").click(function(){ // here i need to add listener again }); 

Je vous remercie.

Vous devez stocker la fonction dans une variable, puis utiliser off pour la supprimer:

 var scrollHandler = function(){ myScroll = $(window).scrollTop(); } $("#itemBind").click(function(){ $(window).scroll(scrollHandler); }).click(); // .click() will execute this handler immediately $("#itemUnbind").click(function(){ $(window).off("scroll", scrollHandler); });