admin管理员组文章数量:1401491
I have simple html page:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" ".dtd">
<html>
<head>
<script src=".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
I have simple html page:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3/TR/html4/loose.dtd">
<html>
<head>
<script src="http://code.jquery./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
Share Improve this question asked Sep 23, 2011 at 11:50 ihorkoihorko 6,95526 gold badges80 silver badges123 bronze badges 03 Answers
Reset to default 3Check http://jsfiddle/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); });
Try this code
if($('.to_hide').css("display") == "block")
{
$(".to_hide").mouseout(function(){
setTimeout(hidepara,10000);
})
}
function hidepara()
{ $(".to_hide").hide();
}
Working sample http://jsfiddle/kaYLG/
This is a very simple solution. Idea is, if you don't move your mouse over the div-container.. it will slideUp()
the container itself in 2000ms (I put 2000ms, because its boring to wait 10sec).
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3/TR/html4/loose.dtd">
<html>
<head>
<script src="http://code.jquery./jquery-latest.js"></script>
<style>
div {width: 400px; border: 1px solid;}
</style>
</head>
<body>
<div>
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>
<script>
$(document).ready(function () {
var mouseover_to = setTimeout(function () {
$("div").slideUp("slow");
}, 2000); // Change it to 10000 to be 10sec
$('div').mouseover(function () {
clearTimeout(mouseover_to);
});
});
</script>
</body>
</html>
[ View output ]
- First it will wait till the document is ready
- It will start the countdown to 2000ms with
setTimeout()
and sets it as resource tomouseover_to
variable. - However, if
mouseover()
is detected over thediv
then the countdown will be canceled withclearTimeout()
, thanks to the help of the resourcemouseover_to
本文标签: javascriptJQuery slideToggle timeoutStack Overflow
版权声明:本文标题:javascript - JQuery slideToggle timeout - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744305265a2599780.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论