JQuery slideToggle超时 [英] JQuery slideToggle timeout
本文介绍了JQuery slideToggle超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有简单的html页面:
<!DOCTYPE HTML PUBLIC - // W3C // DTD HTML 4.01 Transitional // ENhttp://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(慢);
});
});
< / script>
< style>
div {width:400px; }
< / style>
< / head>
< body>
<按钮>切换< /按钮>
< div style =border:1px solid>
这是结束所有段落的段落。您
应感到< em>幸运< / em>看到你的生活这样的一段
。恭喜!
< / div>
< / body>
< / html>
如果鼠标光标不在面板上,我需要在10秒后自动隐藏div面板。
我该怎么做(改变上面的代码)来实现它?
谢谢
解决方案
检查 http://jsfiddle.net/XRYLk/3/
我添加了mouseleave,所以如果鼠标在第一个函数启动时覆盖它,它会在mouseleave上设置计时器。
jQuery:
$ b
$(button {
$(div)。slideToggle(slow);
});
setTimeout(hidepanel,4000);
$ b $ function hidepanel(){
if($('div')。is(':hover')=== false){$('div')。slideToggle(); }
$ b $('div')。mouseleave(function(){setTimeout(hidepanel,4000);});
I have simple html page:
<!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>
I need to hide the div panel automaticaly after 10 seconds if my mouse cursor isn't over the panel. How can I do it (change the code above) to implement that?
Thanks
解决方案
Check http://jsfiddle.net/XRYLk/3/
I added mouseleave so in case the mouse was over it when first function fires up, it will set timer on 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); });
这篇关于JQuery slideToggle超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文