开发者

remove html with jquery before carousel plugin runs

开发者 https://www.devze.com 2023-03-12 00:19 出处:网络
I am trying to remove html from an unordered list based on missing images, this is what I\'m using $(\"img\").error(function () {

I am trying to remove html from an unordered list based on missing images, this is what I'm using

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

which strips out the list entry fine. The problem is that the images are used in a carousel, controlled by http://www.thomaslanciaux.pro/jquery/jquery_carousel开发者_开发知识库.htm and they are counted before they are removed which results in blank frames.

any suggestions in getting this code to run in a way which removes the html before the carousel processes it would be greatly appreciated.


You can add another listener on load $('img').load(...) that keeps track of all images, and once all images have been loaded or error'd out, you load the carousel plugin.

For example:

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();
});
0

精彩评论

暂无评论...
验证码 换一张
取 消