0

在这个页面上,悬停在一个文本上会附加一个带有幻灯片效果的文本的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>
            <h1 style = "width: 299px" id = "text1">Hover to see the truth</h1>
        </div>
    </body>
</html>

脚本.js

$(document).ready (function() {
    $(document).on ("mouseenter", "#text1", function() {

        $("body").append ("<div style = 'background-color: red; width: 299px' id = 'descr'></div>");
        $("#descr")
            .hide()
            .append ("<h3>You're an idiot</h3>")
            .slideDown ("slow");
    });

    $(document).on ("mouseleave", "#text1", function() {
        $("#descr").slideUp ("slow", function() {
            $(this).remove();
        });
    });
});
4

1 回答 1

1

添加附加 html 具有固定高度的样式标记。例如:将您的 .append 方法更改为:

append("<h3 style="height:100px">You're an idiot</h3>")
于 2013-06-24T08:00:03.477 回答