gpt4 book ai didi

jquery - 如何让 jQuery 幻灯片在鼠标悬停时暂停?

转载 作者:行者123 更新时间:2023-12-01 01:36:22 25 4
gpt4 key购买 nike

下面是代码...

var currentImage;

var currentIndex = -1;

var interval;function showImage(index){if(index < $('#bigPic img').length){

var indexImage = $('#bigPic img')[index]

if(currentImage){

if(currentImage != indexImage ){

$(currentImage).css('z-index',2);

clearTimeout(myTimer);

$(currentImage).fadeOut(600, function() {myTimer = setTimeout("showNext()", 10000);$(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 img').length;
var next = currentIndex < (len-1) ? currentIndex + 1 : 0;
showImage(next);
}

var myTimer;

$(document).ready(function() {myTimer = setTimeout("showNext()", 14000);showNext(); //loads first image

$('#thumbs li').bind('click',function(e){

var count = $(this).attr('rel');

showImage(parseInt(count)-1);

});});

最佳答案

我在jsfiddle上放了一个简单的例子。下次别忘了上传您的样式和 html 代码。 (我随机生成)

http://jsfiddle.net/ppFrE/14/

<div id="bigPic">
<img src="http://www.google.com/logos/2012/uganda12-hp.jpg">
<img src="http://www.google.com/logos/2012/janusz-korczak-2012-hp.jpg">
<img src="http://www.google.com/logos/2012/Brazil_Elections-2012-hp.jpg">
</div>
<ul id="thumbs">
<li><img src="http://www.google.com/logos/2012/uganda12-hp.jpg"></li>
<li><img src="http://www.google.com/logos/2012/janusz-korczak-2012-hp.jpg"></li>
<li><img src="http://www.google.com/logos/2012/Brazil_Elections-2012-hp.jpg"></li>
</ul>​

这是完整的 Javascript 代码。

var currentImage;
var currentIndex = -1;
var interval;
var myTimer;
var hover = false;

function showImage(index) {
if (index < $('#bigPic img').length) {
var indexImage = $('#bigPic img')[index]
if (currentImage) {
if (currentImage != indexImage) {
$(currentImage).css('z-index', 2);
clearTimeout(myTimer);
$(currentImage).fadeOut(600, function() {
if (!hover) myTimer = setTimeout(showNext, 1000);
$(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 img').length;
var next = currentIndex < (len - 1) ? currentIndex + 1 : 0;
showImage(next);
}

$(document).ready(function() {
myTimer = setTimeout(showNext, 1000);
showNext(); //loads first image
$('#thumbs li').bind('click', function(e) {
var count = $(this).attr('rel');
showImage(parseInt(count) - 1);
});
$('#bigPic img').hover(function() {
hover = true;
clearTimeout(myTimer);
}, function() {
myTimer = setTimeout(showNext, 1000);
hover = false;
});
});​

关于jquery - 如何让 jQuery 幻灯片在鼠标悬停时暂停?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12810356/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com