我想在元素滚动到 View 时加载它们以减少服务器负载,例如缩略图,但希望它们的占位符 divs
在页面加载时存在。为此,我认为当 div
可见时我需要某种触发器。
jquery-appear有人建议但我似乎无法从任何地方获得它的副本(谷歌给我一个 403 错误)
还有人知道怎么做吗?
最佳答案
我认为 jQuery way points 是您可能需要的插件:
http://imakewebthings.com/jquery-waypoints/
下面是调用航点插件的方法:
$(document).ready(function() {
var $loading = $("<div class='loading'><p>Loading more items…</p></div>"),
$footer = $('footer'),
opts = {
offset: '100%'
};
$footer.waypoint(function(event, direction) {
$footer.waypoint('remove');
$('body').append($loading);
$.get($('.more a').attr('href'), function(data) {
var $data = $(data);
$('#container').append($data.find('.article'));
$loading.detach();
$('.more').replaceWith($data.find('.more'));
$footer.waypoint(opts);
});
}, opts);
});
关于javascript - 当 HTML 元素滚动到 View 中时是否会触发 Javascript 事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13600108/