取消绑定jQuery的特定功能 [英] Unbind a specific function jQuery

查看:104
本文介绍了取消绑定jQuery的特定功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做的是在运行一次之后解除对特定功能的绑定.在下面的代码中是窗口滚动.

What I'm trying to do is unbind a specific function, after it has run once. In the code below it's the window scroll.

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

基本上,当#div淡出时,我希望它滚动到topTop(0).滚动顶部后,我需要整个功能解除绑定.

Basicly, when the #div fades out, I want it to scrollTop(0). After scrolling top, I need this entire function to unbind.

有没有一种方法可以给该函数指定一个特定的名称,然后再调用该名称?因为此代码有效,所以只有它才能删除所有滚动功能. (我当然不希望如此)我在想这样的事情:

Is there a way to give this function a specific name, and then call back that name? Because this code works, only it removes all scroll functions. (Wich ofcourse I don't want) I was thinking something like so:

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

推荐答案

杰斐逊,类似...

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

现在,取消绑定滚动条-我有一个唯一的标识符,以防万一您有其他窗口滚动事件,而又不想弄乱.

now, unbind the scroll - I have it a unique identifier just in case you have other window scroll events, you don't want to mess with.

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

这篇关于取消绑定jQuery的特定功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆