首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >jQuery:在slideDown()和slideUp()时附加固定高度的div

jQuery:在slideDown()和slideUp()时附加固定高度的div
EN

Stack Overflow用户
提问于 2013-06-24 07:54:37
回答 1查看 606关注 0票数 0

在此页面上,悬停在文本上的div附加有幻灯片效果的文本,但问题是在效果之后,它的高度是不稳定的。我怎样才能固定高度?

index.html

代码语言:javascript
复制
<!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>

script.js

代码语言:javascript
复制
$(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();
        });
    });
});
EN

Stack Overflow用户

回答已采纳

发布于 2013-06-24 08:00:03

添加一个固定高度的样式标记。示例:将.append方法更改为:

代码语言:javascript
复制
append("<h3 style="height:100px">You're an idiot</h3>")
票数 1
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17270510

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档