gpt4 book ai didi

javascript - 当 HTML 元素滚动到 View 中时是否会触发 Javascript 事件?

转载 作者:太空狗 更新时间:2023-10-29 15:06:01 25 4
gpt4 key购买 nike

我想在元素滚动到 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&hellip;</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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com