我正在尝试解除一个函数,该函数每2秒在两个html元素之间切换/切换,当鼠标按下这个函数时,应该停止,这样人们就可以看到元素,只要他们愿意。
稍后,我将添加绑定函数,以恢复鼠标退出的切换。
$(document).ready(function () {
function switchBox() {
$('#imagebox7img').toggle('slow', 'linear');
$('#map-canvas').toggle('slow', 'linear');
}
// hide image
$('#imagebox7img').hide();
// set timer and function
setInterval(switchBox, 2000);
// disable function on hover
$('#imagebox7img').mouseover(function () {
$(this).unbind();
});
}); // end ready发布于 2014-02-07 19:48:24
setInterval返回唯一的间隔ID,您可以传递给clearInterval以取消重复操作。
// set timer and function
var interval = setInterval(switchBox, 2000);
$('#imagebox7img').mouseover(function () {
clearInterval(interval )
});https://stackoverflow.com/questions/21636493
复制相似问题