javascript - Remove Scroll event listener used in conjection with throttling function -
please easy....i using throttling function first time scroll.
i have function call which opens particular view on page.
function dayviewopen(target){ var date = getdate(); .. .. .. document.addeventlistener('scroll',throttle(function(event){ scrolladddata(date); },10)); }
similarly have function close particular view
function dayviewclose(target){ .. .. }
everything till working perfectly. problems start arising when have remove earlier added event listener. i.e have remove event listener when call function dayviewclose();
i need have reference listener remove it, when this.
var handler = throttle(function(event){ scrolladddata(); },10); function dayviewopen(target){ var date = getdate(); .. .. .. document.addeventlistener('scroll',handler,false); } function dayviewclose(target){ .. .. //remove earlier added event listener document.removeeventlistener('scroll',handler,false); }
- then not able pass date parameter to handler ( how can pass date parameter handler ) and
- even if let go of date param not able remove handler removeevent listener. ( how can remove event listener properly )
any apreciated
you can try declaring event listener outside, setting inside:
var handler; function dayviewopen(target){ var date = getdate(); /* ... */ handler = throttle(function(event){ scrolladddata(date); }, 10); document.addeventlistener('scroll', handler, false); } function dayviewclose(target){ /* ... */ document.removeeventlistener('scroll', handler, false); }
Comments
Post a Comment