Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple scroll event definition, and discriminatory event unbinding

I ask a specific question about jquery scroll events, but it seems like the answer could have implications to jquery events in general (which I am also interested in knowing).

Suppose that jquery plugin A (e.g., jquery.scrollspy.js) binds a scroll event to $(window)

Now say that some site imports plugin A, but it also has its own custom javascript file B, which binds another .scroll() event to $(window).

Later on, javascript file B wants to unbind its own scroll event, and leave jquery plugin A intact. How is this done?

and...

Is this method universal to all jquery events?

like image 211
Colin Brogan Avatar asked Apr 21 '13 20:04

Colin Brogan


1 Answers

jQuery recommends to use on and off instead of bind and unbind.

function scrollEvent()
{
}
$(window).on('scroll',scrollEvent);
$(window).off('scroll',scrollEvent);

http://api.jquery.com/on/

like image 60
Ruben-J Avatar answered Nov 16 '22 03:11

Ruben-J