Untie a specific jQuery function

What I'm trying to do is unbind a specific function after it starts. In the code below, the window scrolls.

 $(window).scroll(function(){
     if($(window).scrollTop() == viewportheight ){
          $("#landing_page").fadeOut(function() { $(window).scrollTop(0); $(window).unbind("scroll");});
     }
 });

Basically, when #div disappears, I want it to scroll Top (0). After scrolling from the top, I need all this function to unlock.

Is there a way to give this function a specific name and then call that name? Since this code works, only it removes all the scroll functions. (Of course I don't want to) I thought something like this:

 $(window).scroll(function(FUNCTION NAME HERE){
     if($(window).scrollTop() == viewportheight ){
          $("#landing_page").fadeOut(function() { $(window).scrollTop(0); $(window).unbind("FUNCTION NAME HERE");});
     }
 });
+5
source share
2 answers

Jefferson, something like ...

$(window).bind("scroll.myScroll", function(){
     // stuff
  })

now untie the scroll - I have a unique identifier just in case, if you have other window scroll events, you do not want to communicate.

$(window).unbind('.myScroll');
+23

jquery.unbind,

0

All Articles