2011-06-30 59 views
0

我很新的jQuery和JavaScript的一般,所以很抱歉,如果这是一个简单的问题。任何帮助将非常感激。我有一个幻灯片自动分页,我希望它,所以当你点击控制器(#thumbs锂)节目暂停。这是JS:Jquery幻灯片脚本,暂停点击

<script type="text/javascript"> 
var currentImage; 
var currentIndex = -1; 
var interval; 
function showImage(index){ 
    if(index < $('#bigPic div').length){ 
     var indexImage = $('#bigPic div')[index] 
     if(currentImage){ 
      if(currentImage != indexImage){ 
       $(currentImage).css('z-index',2); 
       clearTimeout(myTimer); 
       $(currentImage).fadeOut(400, function() { 
        myTimer = setTimeout("showNext()", 3500); 
        $(this).css({'display':'none','z-index':1}) 
       }); 
      } 
     } 
     $(indexImage).css({'display':'block', 'opacity':1}); 
     currentImage = indexImage; 
     currentIndex = index; 
     $('#thumbs li').removeClass('active'); 
     $($('#thumbs li')[index]).addClass('active'); 
    } 
} 

function showNext(){ 
    var len = $('#bigPic div').length; 
    var next = currentIndex < (len-1) ? currentIndex + 1 : 0; 
    showImage(next); 
} 

var myTimer; 

$(document).ready(function() { 
    myTimer = setTimeout("showNext()", 3500); 
    showNext(); //loads first image 
    $('#thumbs li').bind('click',function(e){ 
     var count = $(this).attr('rel'); 
     showImage(parseInt(count)-1); 
    }); 
}); 


</script> 
+0

就这么你知道,有一个叫做Lightbox Slideshow的jQuery插件(http://www.justinbarkhuff.com/lab/lightbox_slideshow/),它提供了所有这些功能和更多功能。这很好,你也可以自己学习。但是,我想让你知道这件事。 – JasCav

回答

0

我会做一个函数来开始幻灯片放映以及停止这样的事情。

// must be set to declare that we're using it later. 
var myTimer; 

function startShow(){ 
    myTimer = setTimeout("showNext()", 3500); 
} 
function stopShow(){ 
    clearTimeout(myTimer); 
} 

$(document).ready(function() { 
    startShow(); 
    showNext(); //loads first image 
    $('#thumbs li').bind('click',function(e){ 
     var count = $(this).attr('rel'); 
     showImage(parseInt(count)-1); 
    }); 
    // you're going to want to hide this element initially, until the user pauses the slide show, vice versa. 
    $('#selectorToStartShow').bind('click',function(){ 
    startShow(); 
    }); 
    $('#selectorToPauseShow').bind('click',function(){ 
    stopShow(); 
    }); 
}); 

我不知道你想与#thumbs里点击该怎么做,但应该做的伎俩。

+0

感谢您的帮助。我非常接近,但由于某种原因,我必须点击两次停止按钮。 – Ben

+0

添加上面的代码片段后? –