我创建了一个对 simple.carousel.js 的编辑以在悬停时停止轮播,但是当鼠标离开时我遇到了重新启动它的问题。我添加到 simple.carousel.js 的代码是:
// hover stop
if(config.auto!=true)
$(this).mouseenter(function() {
config.auto=false;
}).mouseleave( function() {
config.auto=true;
});
您可以在此处查看完整代码/示例以及我从上面添加的内容:http://jsfiddle.net/6r6sC/2/
我的 mouseleave 功能有问题吗?
不确定这是否会有所帮助,但我也尝试了以下方法,但这也不起作用:
// hover stop
if(config.auto!=true)
$(this).mouseenter(function() {
config.auto=false;
}).mouseleave( function() {
setTimeout(function() {
slide('next');
}, config.auto);
});
任何帮助将不胜感激,因为这让我很难过。
最佳答案
使用 true 作为值是一个问题,导致 false boolean 或 int 预期来自您的 init 函数。
编辑 4:
http://jsfiddle.net/6r6sC/44/
在 slide() 中,添加了 startAuto()
if(config.auto!=false) {
startAuto();
}
编辑3:
修复了多个定时器的问题,并创建了两个函数来处理启动/停止自动滑块。
这里的解决方案:http://jsfiddle.net/6r6sC/41/
var cachedAuto = config.auto;
var timer = "";
var startAuto = function() {
config.auto = cachedAuto;
clearTimeout(timer);
timer = setTimeout(function() {
slide('next');
}, config.auto);
}
var stopAuto = function() {
clearTimeout(timer);
config.auto = false;
}
if(config.auto!=false) {
// start auto sliding
startAuto();
// pause/start on mouse events
$(this).on("mouseenter", function(event){
stopAuto();
}).on("mouseleave", function(event){
startAuto();
});
}
关于jquery - mouseenter mouseleave jquery 悬停和重启问题与 simple.carousel.js,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13612816/