我有简单的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() {
$("div").hide();
$("button").hover(function() {
$("div").slideDown("slow");
});
setTimeout(hidepanel, 4000);
function hidepanel() {
if ($('div').is(':hover') === false) {
$('div').slideUp();
}
}
$('div').mouseleave(function() { setTimeout(hidepanel, 4000); });
$('button').mouseleave(function() { setTimeout(hidepanel, 4000); });
});
</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>
我需要:
我的代码应该改变什么?
非常感谢!
答案 0 :(得分:1)
有趣的部分是在面板/按钮外部单击时隐藏面板。
$(document).click(function (e) {
if (e.target.id !== "btn" && e.target.id !== 'panel' && $(e.target).parents('#panel').length === 0)
{
hidepanel();
}
});
答案 1 :(得分:-2)
显然,你会想要选择器比“DIV”和“按钮”更具体,但你明白了。