无法重新绑定滚动事件? [英] Can not rebind scroll event?
问题描述
$(window).scroll(function(){
column_height = $(#first_column)。height();
screenTop = $(window).scrollTop();
window_height = $(window).height();
$(
)
$ .ajax({
url:/service/article_json.php,
type:'GET',
async:false,
cache:false,
timeout :$ 300
错误:function(){
return true;
},
success:function(data){
$ .each($。parseJSON ),function(key,item){
//将内容添加到#first_column
$(window).bind('scroll');
});
}
});
}
});
$(window).bind('scroll');
似乎不工作。
当您 .unbind
对绑定事件的引用不是存储在任何地方或什么 $(window).bind('scroll')
实际上什么也没有。
首先,如果你正在使用 1.7
应该使用 .on
和 .off
。没有什么大不了的。
有几种方法可以做到这一点,但最简单的方法是单独定义函数,并使用其名称来绑定/取消绑定。你甚至可以将它附加到窗口(虽然我认为只是使用函数
关键字这样做。Anyway ..)
$(window).data('scrollEvent',function(){/ *你的func这里* /});
$(window).on('scroll',$(window).data('scrollEvent'));
您可以使用第二行替换 $(window).bind 'scroll')
以上。小心递归。
I want to rebind window scroll event in ajax call
$(window).scroll(function(){
column_height = $("#first_column").height();
screenTop = $(window).scrollTop();
window_height = $(window).height();
if((screenTop+window_height)>=column_height){
$(window).unbind('scroll');
$.ajax({
url: "/service/article_json.php",
type: 'GET',
async: false,
cache: false,
timeout: 30000,
error: function(){
return true;
},
success: function(data){
$.each($.parseJSON(data), function(key,item) {
//Add content to #first_column
$(window).bind('scroll');
});
}
});
}
});
The $(window).bind('scroll');
seems not working.
When you .unbind
a reference to the bound event is not stored anywhere or anything. $(window).bind('scroll')
actually does nothing.
First off, if you are using 1.7
you should use .on
and .off
instead. Not a big deal.
There are several ways to do this, but the easiest is to just define the function separately and use its name to bind/unbind. You can even attach it to the window (though I think just using the function
keyword does that. Anyway..)
$(window).data('scrollEvent', function() { /* your func here */ });
$(window).on('scroll', $(window).data('scrollEvent'));
You can use that second line to replace $(window).bind('scroll')
above. Beware of the recursion.
这篇关于无法重新绑定滚动事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!