我一直在想办法让这个函数在鼠标悬停时暂停,并在鼠标移出时继续。我已经想出如何在鼠标悬停时暂停该功能,但它不会在鼠标移出时再次启动。这是 jQuery 代码(从另一个教程中使用)。
function swapImages(){
var $active = $('#myGallery .active');
var $next = ($('#myGallery .active').next().length > 0) ? $('#myGallery .active').next() : $('#myGallery img:first');
$active.fadeOut(function(){
$active.removeClass('active');
$next.fadeIn().addClass('active'); }); }
$(document).ready(function(){setInterval('swapImages()', 5000);}
$('#myGallery').mouseover(function(){
$(this).delay(60000);
});
最佳答案
使用 jQuery 的 hover
$( selector ).hover( handlerIn, handlerOut )
简称
$( selector ).mouseenter( handlerIn ).mouseleave( handlerOut );
关于jquery - 如何为这个 jquery 函数添加一个暂停?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22079509/