2011-11-17 94 views
1

我剛剛意識到我搞砸了我的最後一個問題。獲取div的高度javascript動態內容加載到它

我使用下面的腳本來獲取DIV#tweet-area的動態高度並將該高度插入到CSS中。

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

它的工作方式BEAUT但我才意識到它變得高度,是我的Twitter內容之前的div的高度被加載。我的Twitter內容由jQuery插件生成,請參見下文。

我使用這個jQuery插件,嘰嘰喳喳 - tweet.seaofclouds.com/jquery.tweet.js

和裝載這樣的腳本 -

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

林加載到微博#DIV最新的鳴叫是DIV#鳴叫區域內。見下面

<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> 

任何幫助將是真棒,因爲這是對我來說有點專家。感謝沿線的這麼多

回答

3

試試:

<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處理程序的調用一個不良記錄來電者。祝你好運!

+0

完美的傢伙,謝謝這麼多人! - 謝謝你看看,我不會發現這個處理程序 - 儘管我以前從未使用.bind,但現在肯定。 – Joshc

2

的seaofclouds插件沒有回調,而是有鳴叫時的裝載已經完成其發射的loaded事件。

因此,以下應爲你工作:

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

yep完美謝謝 - 謝謝你的解釋! – Joshc

1

上的插件229行,你看

$(widget).trigger("loaded") 

這會觸發你綁定的鳴叫股利事件loaded。所以你可以做

$("#latest-tweet").tweet({  
    // options 
}).bind("loaded", function(){ 
    // calc height 
}); 
+0

是的,只是看看裏面的插件 - 謝謝你向我解釋這個,幫助很多! – Joshc

+0

的歡迎@ user801773 –

+0

您好,我知道這是一個有點厚臉皮,但你熟悉我的問題前,請你看看這個[http://goo.gl/NWNx8](http://goo .gl/NWNx8) - 可以通過PayPal捐贈,如果你能幫助:) – Joshc