由网友(不羁的风)分享简介:我做了这个无限滚动的剧本,但我不能重新绑定窗口滚动后,我unbinded它。这里的脚本:$(函数(){$(窗口).scroll(函数(){VAR mostOfTheWayDown =($(文件).height() - $(窗口).height())* 2/3;如果($(窗口).scrollTop()> = mo...
我做了这个无限滚动的剧本,但我不能重新绑定窗口滚动后,我unbinded它。这里的脚本:
$(函数(){
$(窗口).scroll(函数(){
VAR mostOfTheWayDown =($(文件).height() - $(窗口).height())* 2/3;
如果($(窗口).scrollTop()> = mostOfTheWayDown){
$(窗口).unbind(滚动);
$阿贾克斯({
网址:loadmore,
数据:{lastrank:lastrank},
数据类型:JSON,
键入:POST,
成功:函数(JSON){
//一些工作在这里
$(窗口).bind(滚动);
}
});
}
});
});
我怎样才能重新绑定窗口滚动一个成功的Ajax调用后?
解决方案 $(函数(){
VAR scrollFunction =功能(){
VAR mostOfTheWayDown =($(文件).height() - $(窗口).height())* 2/3;
如果($(窗口).scrollTop()> = mostOfTheWayDown){
$(窗口).unbind(滚动);
$阿贾克斯({
网址:loadmore
数据:{lastrank:lastrank},
数据类型:JSON,
键入:POST,
成功:函数(JSON){
//一些工作在这里
$(窗口).scroll(scrollFunction);
}
});
}
};
$(窗口).scroll(scrollFunction);
});
I have made this infinitely scrolling script, but I can't rebind the window scroll after I unbinded it. Here's the script:
$(function(){
$(window).scroll(function(){
var mostOfTheWayDown = ($(document).height() - $(window).height()) * 2 / 3;
if ($(window).scrollTop() >= mostOfTheWayDown) {
$(window).unbind('scroll');
$.ajax({
url: 'loadmore',
data: {lastrank: lastrank},
dataType: 'json',
type: 'POST',
success: function(json){
//some work here
$(window).bind('scroll');
}
});
}
});
});
How can I rebind the window scroll after a successful ajax call?
解决方案$(function(){
var scrollFunction = function(){
var mostOfTheWayDown = ($(document).height() - $(window).height()) * 2 / 3;
if ($(window).scrollTop() >= mostOfTheWayDown) {
$(window).unbind("scroll");
$.ajax({
url: "loadmore",
data: {lastrank: lastrank},
dataType: "json",
type: "POST",
success: function(json){
//some work here
$(window).scroll(scrollFunction);
}
});
}
};
$(window).scroll(scrollFunction);
});
相关推荐
最新文章