Javascript 在鼠标上方停止幻灯片放映
我有一个幻灯片,在3个不同的图像之间切换,这些图像在Javascript 在鼠标上方停止幻灯片放映,javascript,jquery,html,mouseover,Javascript,Jquery,Html,Mouseover,我有一个幻灯片,在3个不同的图像之间切换,这些图像在DIV标签中分开。我希望当你将鼠标悬停在幻灯片上时,它应该停止,当你将鼠标从幻灯片上取下时,它应该继续滚动 代码如下: function slideSwitch() { var $active = $('#slideshow3 div.active3'); if ($active.length == 0 ) $active = $('#slideshow3 div:last'); var $next = $active
DIV
标签中分开。我希望当你将鼠标悬停在幻灯片上时,它应该停止,当你将鼠标从幻灯片上取下时,它应该继续滚动
代码如下:
function slideSwitch() {
var $active = $('#slideshow3 div.active3');
if ($active.length == 0 ) $active = $('#slideshow3 div:last');
var $next = $active.next().length ? $active.next() : $('#slideshow3 div:first');
$active.addClass('last-active3')
.animate({opacity : 0.0}, 1000);
$next.css({opacity: 0.0})
.addClass('active3')
.animate({opacity: 1.0}, 1000, function() {
$active.removeClass('active3 last-active3');
});
}
首先,我尝试过这样做:
$("#slideshow3").mouseover(function(){
$(this).stop();
return false;
});
但是幻灯片甚至没有停止,所以我肯定没有正确地瞄准它,也没有将代码放在正确的位置
你能给我一些建议吗
谢谢大家! 您可以将间隔引用存储在变量中,然后在悬停图像时停止间隔,退出时启动间隔 代码:
演示:使用队列和clearQueue而不是Stop。您可以共享一把小提琴吗?您在哪里调用此函数?slideSwitch?很抱歉,我忘了包含调用,但我在下面将其命名为:$(function(){setInterval(“slideSwitch()”,3000);这是小提琴:我不明白为什么它没有运行,但它在图像旁边看起来或多或少与我的相同。谢谢你Irvin,正是我所需要的。感谢:)
var theInterval;
function startSlide() {
theInterval = setInterval(slideSwitch, 5000);
}
function stopSlide() {
clearInterval(theInterval);
}
$(function () {
startSlide();
$('#slideshow DIV').hover(function () {
stopSlide();
}, function () {
startSlide();
})
});