【发布时间】:2014-01-30 10:50:11
【问题描述】:
我有一个幻灯片,可以在DIV 标签中分隔的 3 个不同图像之间切换。我希望当您将鼠标悬停在幻灯片上时它应该停止,当您将鼠标从幻灯片上移开时它应该继续滚动。
代码在这里:
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;
});
但是幻灯片甚至没有停止,所以我肯定没有正确定位它或将代码放在正确的位置。
你能给我一些建议吗?
谢谢!
【问题讨论】:
-
使用 queue 和 clearQueue 而不是 stop
-
你能分享一下小提琴吗?
-
你在哪里调用这个函数?滑动开关?
-
对不起,我忘了包括调用,但我在下面将其称为:$(function(){ setInterval("slideSwitch()", 3000);
-
这里是小提琴:jsfiddle.net/F86jv我不明白为什么它不运行,它看起来和我的图像旁边的差不多。
标签: javascript jquery html mouseover