所有图像加载后循环功能运行一次

时间:2014-05-03 10:53:27

标签: jquery initialization cycle

我在幻灯片div中有图像,我想要居中。每个幻灯片后都会运行“已加载”功能,有没有办法在所有图像上运行一次该功能?

    // start jQuery Cycle   
    .cycle({ 
         startingSlide: startSlide,
         // when using the next/prev links
     onPrevNextEvent: function(isNext, idx, slide) { 
        hasSlid = 1;
        window.location.hash = (parseInt(idx) + 1) + ""; 
        return false;
     },
     // when using the pager thumbnails
     onPagerEvent: function(idx, slide) { 
        hasSlid = 1;
        window.location.hash = (parseInt(idx) + 1) + ""; 

        return false;
     },
     timeout: 0, 
     fx: 'scrollHorz',
     next: '.cycle-next',
     prev: '.cycle-prev',
     speed: 200,
     after: loaded,

    });


function loaded(curr,next,opts) {

        $('.slide .image img').each(function(){

        var height = $(this).height();
        var width = $(this).width();

        $(this).css('margin-top','-' + height/2 +'px');
        $(this).css('margin-left','-' + width/2 +'px');

        $('img').animate({opacity:1},150)
    });
};

1 个答案:

答案 0 :(得分:0)

当然,在事件发生后调用加载的页面加载而不是循环:

$('body').on('load', loaded);