Jquery更改.click函数自动更改

时间:2013-04-15 14:20:34

标签: jquery onclick gallery

我使用下面的代码显示一个大的全屏滑块。我试图做的是将.click函数替换为定时事件,以便每个图像在一段时间(比如7秒)后更改,而不是在单击链接时更改。

已经工作了半天,我仍然被困住,所以你能提供的任何帮助都会非常感激。

由于

戴夫

    jQuery(function($){
    $(document).ready(function(){

    $('.panorama .panorama-view').panorama360();
if ($('.panorama #thumbnails .thumbers a').length > 1) { // check if there are multiple panoramas
    $('.panorama .panorama_controls a').click(function(ev) {
        ev.preventDefault();
        $active = $('.panorama #thumbnails .thumbers a.active');
        if ($(this).hasClass('panorama_next')) {
            if ($active.length == 0) $active = $('.panorama #thumbnails .thumbers a:last');
            $next = $active.parent().next('li');
            console.log($next);
            if ($next.length > 0) { // check to see if it's not the first thumb
                $('a:first',$next).trigger('click');
            } else { // load last panorama in the thumb stack
                $('.panorama #thumbnails .thumbers:first a').trigger('click');
            }
        }
        else {
            if ($active.length == 0) $active = $('.panorama #thumbnails a:first');
            $prev = $active.parent().prev('li');
            if ($prev.length > 0) { // check to see if it's not the first thumb
                $('a:first',$prev).trigger('click');
            } else { // load last panorama in the thumb stack
                $('.panorama #thumbnails .thumbers:last a').trigger('click');
            }
        }
    });
} else { // you can hide the controls because there is only one panorama loaded
    $('.panorama .panorama_controls').hide();
}
$('.panorama #thumbnails .thumbers a').click(function(ev) {
    ev.preventDefault();
    if ($(this).hasClass('active')) return;

    $('.panorama .preloader').show();
    $('#thumbnails .thumbers a').removeClass('active');
    $(this).addClass('active');
    $('.panorama .panorama-view').hide();
    $('.panorama .panorama-container').html($(this).next().html());
    $('.panorama .panorama-view').panorama360({ sliding_direction: 0 });
    $('h1.main-header').html($(this).data("title"));
    $('.main-desc').html($(this).data("description"));

});
$('.panorama .hotspot').fancybox({

        padding     : 0,
        fitToView   : true,
        mouseWheel  : false,
        maxWidth: '600',
        minHeight: '400',

        autoCenter: true,

        closeClick  : false
});

var pictures = [],

    $thumbnails = $( '#thumbnails' );

    // jScrollPane

$thumbnails.find( 'ul' ).width( function() {
    var totalWidth = 0;
    $( this ).find( 'li' ).each( function() {
        totalWidth += $( this ).outerWidth( true );
    });
    return totalWidth;
});

$thumbnails.jScrollPane();

var jScrollPaneApi = $thumbnails.data( 'jsp' );

$( window ).bind( 'resize', function() {
    jScrollPaneApi.reinitialise();
});

    }); // END doc ready
    }); // END function

1 个答案:

答案 0 :(得分:0)

为什么不直接触发点击功能,而不是替换它?

setTimeout(function () {
    $('.panorama .panorama_controls a.panorama_next').click();
}, 7000);