vendredi 30 janvier 2015

JQuery bind/unbind mousewheel event

I am trying to enable and disable scrolling on my page


I have this function :



function scroll_toggle(key){
if (key) {
$(window).bind('scroll', function(){
$('body').on({
'mousewheel': function(e) {
console.log("binded");
$("html body").scrollTop(0);
if (e.target.id == 'el') return;
e.preventDefault();
e.stopPropagation();
}});
});
} else {
$(window).unbind('scroll');
$('body').on({
'mousewheel': function(e) {
console.log("unbinded");
return true;

}});
}
}


When I call this function for the first time with true as parameter, the mousewheel don't work, and a I have "binded" in my console.


But when I call the function with false, the mousewheel still don't work and i have "binded" and "unbinded" alternatively.


What is wrong in my code?


Thanks for your time





Aucun commentaire:

Enregistrer un commentaire