gpt4 book ai didi

jquery - 如果在 .load() 事件处理程序中运行,smoothDivScroll 会失败

转载 作者:行者123 更新时间:2023-12-01 05:55:51 25 4
gpt4 key购买 nike

smoothDivScroll如果在 $(window).load() 内调用,1.3 对我来说会失败。看这个jsFiddle .

.load() 事件处理程序已弃用,因此我尝试使用 imagesLoaded jQuery 插件如下:

(function ($) { if($('.scroller').length)
$('.scroller').imagesLoaded(function() {
$('.scroller').smoothDivScroll({});
});
})(jQuery);

但这在 Safari、Chrome 和 Opera 中也失败了。这些浏览器的控制台中不会显示任何错误。但它可以在 Firefox 中运行。浏览器版本是最新的。

有什么想法为什么会失败吗?

最佳答案

您粘贴的代码片段失败,因为执行该函数时不一定会加载 .scroller,因此返回 length 为 0。只需将其放入 $(document).ready 处理程序。或简称:

$(function() {
$('.scroller').smoothDivScroll({});
});

JSFiddle 为您添加了该功能,但在您的脚本中,您需要将依赖于 DOM 元素的代码包装到这样的函数中。

关于jquery - 如果在 .load() 事件处理程序中运行,smoothDivScroll 会失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15856607/

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