我有简单的 html 页面:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(document).ready(function() {
$("button").click(function() {
$("div").slideToggle("slow");
});
});
</script>
<style>
div { width:400px; }
</style>
</head>
<body>
<button>Toggle</button>
<div style="border: 1px solid">
This is the paragraph to end all paragraphs. You
should feel <em>lucky</em> to have seen such a paragraph in
your life. Congratulations!
</div>
</body>
</html>
如果我的鼠标光标不在面板上,我需要在 10 秒后自动隐藏 div 面板。
我该如何做(更改上面的代码)来实现它?
Thanks
Check http://jsfiddle.net/XRYLk/3/ http://jsfiddle.net/XRYLk/3/
我添加了 mouseleave,这样当第一个函数启动时,如果鼠标位于其上方,它将在 mouseleave 上设置计时器。
jQuery:
$("button").click(function() {
$("div").slideToggle("slow");
});
setTimeout(hidepanel, 4000);
function hidepanel(){
if($('div').is(':hover') === false){ $('div').slideToggle(); }
}
$('div').mouseleave(function(){ setTimeout(hidepanel, 4000); });
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)