我刚刚意识到我在最后一个问题上搞砸了。
我使用下面的脚本获取DIV#tweet区域的动态高度,并将该高度插入CSS。

    var tweetheight = $("#tweet-area").height();
    $("#sidebar-wrapper").css({ bottom: tweetheight});

它的效果很好,但我刚刚意识到它的高度,是在我的twitter内容加载之前div的高度。我的twitter内容是由jQuery插件生成的,如下所示。
我正在使用这个jQuery twitter插件-tweet.seaofclouds.com/jquery.tweet.js
像这样加载脚本-
    $("#latest-tweet").tweet({
        count: 1,
        username: ["motocomdigital"],
        loading_text: "searching twitter...",
    });

我正在将tweets加载到DIV#tweet区域内的最新tweet中。见下文
    <div id="tweet-area" class="clearfix">
        <div id="latest-tweet"></div>
    </div>

我尝试在twitter脚本之后添加我的高度脚本,但仍然获得相同的高度:/
    <script>
        $(document).ready(function() {

                $("#latest-tweet").tweet({
                        count: 1,
                        username: ["motocomdigital"],
                        loading_text: "searching twitter..."
                });

                var tweetheight = $("#tweet-area").height();
                $("#sidebar-wrapper").css({ bottom: tweetheight});

        });
    </script>

任何帮助都会很棒,因为这对我来说是个小专家。非常感谢

最佳答案

尝试一些类似的方法:

    <script>
        $(document).ready(function() {

                $("#latest-tweet").tweet({
                        count: 1,
                        username: ["motocomdigital"],
                        loading_text: "searching twitter..."
                }).bind("loaded", function(){
                        tweetheight = $("#tweet-area").height();
                        $("#sidebar-wrapper").css({ bottom: tweetheight});
                });
        });
    </script>

这在您得到的插件中实现了一个文档记录不好的调用方,它是在代码运行后对loaded处理程序的调用。祝你好运!

关于jquery - 将javascript动态内容加载到其中后,获取div的高度,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8169707/

10-11 20:17
查看更多