I have a function that I use to open a specific view on my webpage.
function dayViewOpen(target){
var date = getDate();
..
..
..
document.addEventListener('scroll',throttle(function(event){
scrollAddData(date);
},10));
}
Similarly, I also have a function to close that particular view
function dayViewClose(target){
..
..
}
Everything was working perfectly up until now. However, issues started arising when I needed to remove the previously added event listener. In other words, I needed to remove the event listener when calling the function dayViewClose();
I understand that we need a reference to the listener in order to remove it. So, when I tried this approach:
var handler = throttle(function(event){
scrollAddData();
},10);
function dayViewOpen(target){
var date = getDate();
..
..
..
document.addEventListener('scroll',handler,false);
}
function dayViewClose(target){
..
..
//remove the previously added event listener
document.removeEventListener('scroll',handler,false);
}
- then I encountered difficulty passing the date parameter to the handler ( how can I pass the date parameter to the handler ) and
- Even if I disregarded the date parameter, I still struggled to properly remove the handler with removeEventListener. ( how can I effectively remove the event listener )
Any assistance would be greatly appreciated