重新检查 jQuery 中的某些内容?
基本上我有一个 jQuery 函数来检查用户是否位于页面底部附近并加载更多内容。当文档加载时,它会运行以进行检查。
<script type="text/javascript">
$(document).ready(function() {
var number = 5;
offset = 0;
$(window).scroll(function() {
if($(window).scrollTop() + $(window).height() > $(document).height() - 10) {
$(".empty-div").append().load('<?php bloginfo('template_url'); ?>/ajax.php?offset='+offset+number, function() {
var offset = offset+number;
setTimeout(function(){ console.log('after', $(document).height()); }, 0);
setTimeout(function(){ console.log('after', $(window).height()); }, 0);
});
}
});
});
</script>
每当我第二次到达页面底部时,它都不会重做加载功能。顺便说一句,第一次确实有效。有什么想法可以解决这个问题吗?控制台的东西是用来重新计算高度的,以防万一这就是导致它的原因。
Basically I have a jQuery function that checks if the user is near the bottom of the page and loads more stuff. When the document loads this is ran, to check.
<script type="text/javascript">
$(document).ready(function() {
var number = 5;
offset = 0;
$(window).scroll(function() {
if($(window).scrollTop() + $(window).height() > $(document).height() - 10) {
$(".empty-div").append().load('<?php bloginfo('template_url'); ?>/ajax.php?offset='+offset+number, function() {
var offset = offset+number;
setTimeout(function(){ console.log('after', $(document).height()); }, 0);
setTimeout(function(){ console.log('after', $(window).height()); }, 0);
});
}
});
});
</script>
H/e whenever I reach the bottom of the page on the second go, it doesn't redo the load function. It does work the first time, by the way. Any ideas how to remedy this? The console stuff is there to recalculate the heights, just in case that's what's causing it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通过这样做:
您正在创建一个新本地
offset
变量,而不是更新函数之前声明的原始变量,因此:
?offset='+offset+ number
始终使用offset
作为0
,因为它从未更新。只需删除var
,如下所示:为了简洁起见,还可以在原始声明中添加
var
,或者使用逗号进行多个声明,如下所示:By doing this:
You're creating a new local
offset
variable, not updating your originaldeclared before the function, so this:
?offset='+offset+number
is always usingoffset
as0
, since it's never updated. Just remove thevar
, like this:For cleanliness, also add a
var
to the original declaration, or use a comma for a multiple declaration, like this:你在 $(".empty-div") 上使用 load() ,这不会添加更多内容,它将替换内容(如果响应没有改变,你将看不到任何变化)
最好应该是这样的
的东西,也许 DOCTYPE 也有问题。日志
也许,标准模式和怪异模式之间有所不同。
you use load() there on $(".empty-div"), this would'nt add more content, it will replace the content(if the response does'nt change, you will see no change)
It better should be something like
maybe there also is a problem with the DOCTYPE. Log
maybe, it differs between standards - and quirks-mode.