我对jquery和javascript很新,所以很抱歉,如果这是一个简单的问题。任何帮助将非常感激。我有一个幻灯片自动分页,我想要它,所以当你点击控制器(#thumbs li)时,节目暂停。这是JS:
<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 :(得分: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 li点击做什么,不过这应该可以解决问题。