在下一页上,将鼠标悬停在文本上会附加一个带有幻灯片效果的文本的 div。问题是,当它向上滑动以删除 div 时,再次在文本上输入鼠标会停止滑动,并且 div 仍然没有文本。快速进入和离开会附加 div。在这种情况下,我怎样才能继续向下滑动?
索引.html
<!DOCTYPE html>
<html>
<head>
<script src = "http://code.jquery.com/jquery-1.10.1.min.js" type = "text/javascript"></script>
<script src = "script.js" type = "text/javascript"></script>
</head>
<body>
<div id = "main_div" style = "width: 33%">
<div id = "hover_div">
<h1 style = "width: 300px; background-color: blue; margin: 0; border: 1px solid #DDDDDD" id = "text1">Hover to see the truth</h1>
</div>
</div>
</body>
</html>
脚本.js
$(document).ready (function() {
$(document).on ("mouseenter", "#text1", function() {
$("#main_div").append ("<div style = 'background-color: red; width: 300px; height: 200px; margin: 0; border: 1px solid #DDDDDD' id = 'descr'></div>");
$("#descr")
.hide()
.append ("<h3 id = 'truth' style = 'float: left; height: 100px'>You're an idiot</h3>")
.slideDown ("slow");
});
$(document).on ("mouseleave", "#text1", function() {
$("#descr").slideUp ("slow", function() {
$(this).remove();
});
});
$(document).on ("mouseenter", "#descr", function() {
$("#descr").slideUp ("slow", function() {
$(this).remove();
});
});
});
演示:小提琴