我想在ajax调用中重新绑定窗口滚动事件
$(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');
似乎不起作用。
当你.unbind
对绑定事件的引用不会存储在任何地方或任何内容。$(window).bind('scroll')
实际上什么也没做。
首先,如果您正在使用1.7
你应该使用.on
and .off
反而。没什么大不了的。
有多种方法可以做到这一点,但最简单的方法是单独定义函数并使用其名称来绑定/取消绑定。你甚至可以将它附加到窗户上(尽管我认为只使用function
关键字就是这样做的。反正..)
$(window).data('scrollEvent', function() { /* your func here */ });
$(window).on('scroll', $(window).data('scrollEvent'));
您可以使用第二行来替换$(window).bind('scroll')
多于。当心递归。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)