gpt4 book ai didi

jquery - 在轮播插件运行之前使用 jquery 删除 html

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

我正在尝试根据丢失的图像从无序列表中删除 html,这就是我正在使用的

$("img").error(function () {
$(this).parent().remove();
});

它可以很好地删除列表条目。问题是图像在轮播中使用,由 http://www.thomaslanciaux.pro/jquery/jquery_carousel.htm 控制。并且在删除之前对它们进行计数,从而导致空白帧。

任何关于让此代码以在轮播处理之前删除 html 的方式运行的建议将不胜感激。

最佳答案

您可以在加载时添加另一个监听器 $('img').load(...) 来跟踪所有图像,一旦所有图像都已加载或出错,您加载轮播插件。

例如:

var startCarousel, imgCount = $('img').length;

startCarousel = function() {
if (imgCount === 0) {
$('img').carousel(); // TODO adjust this to match the way you start your carousel
}
}

$('img').load(function() {
imgCount--;
startCarousel();
})
.error(function() {
imgCount--;
$(this).parent().remove();
startCarousel();
});

关于jquery - 在轮播插件运行之前使用 jquery 删除 html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6278609/

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