Note that there are some explanatory texts on larger screens.

plurals
  1. POjquery animate variable from bound function
    primarykey
    data
    text
    <p><a href="http://jsfiddle.net/motocomdigital/c8Mey/1/" rel="nofollow">http://jsfiddle.net/motocomdigital/c8Mey/1/</a></p> <p>I'm using a twitter script which i'm binding a function to get the dynamic height of div#tweet, once the tweet has loaded.</p> <p>But I then need to pass that variable into a .animate script after - this is what I got so far.</p> <pre><code> $("#tweet").tweet({ count: 1, username: ["motocomdigital"], loading_text: "searching twitter...", intro_text: null, outro_text: null }).bind("loaded", function(){ // this binded function is getting the height of tweet div once loaded... var tweetHeight = $("#tweet").height(); }); </code></pre> <p>I then need to pass the variable <strong>tweetHeight</strong> into an animation script i'm running below. Simple I thought but I think I'm coding it slightly wrong.</p> <pre><code> $latestTweet.hover(function() { // see variable in this is first alternation $latestTweet.stop().animate({ top: "-" + tweetHeight + "px", width: "512px", }, function() { $latestTweet.stop().animate({ top: "-1px", width: "334px", backgroundColor: "#464848" }, 300); }); </code></pre> <p>Lets say the div#tweet height (once the twitter content is loaded) is 200px, I need the result of this variable to be...</p> <pre><code>$latestTweet.stop().animate({ top: "-200px", width: "512px", </code></pre> <p>Can anyone help me understand how write this correctly - I've even tried putting my animate scripts inside the binded function, but still its not passing the variable.</p> <p><strong>MAJOR UPDATE</strong></p> <p>Ive just figured out why its giving the wrong height of the #tweet div! Its because my #tweet div has top and bottom padding, and the <strong>.height</strong> is not including those dimensions when creating the <strong>tweetHeight</strong> variable, see <a href="http://jsfiddle.net/motocomdigital/c8Mey/1/" rel="nofollow">jsfiddle here</a></p> <p>Does anyone know how I can add fixed pixel dimensions to my <strong>tweetHeight</strong> variable? For example an extra 50px?</p> <p>The reason also why I'm binding it to the twitter javascript is because the height of the #tweet div is dynamic in height, hence the animation from the top position, always need the final height of the #tweet div to position it perfect. See for simplified demo <a href="http://jsfiddle.net/motocomdigital/c8Mey/1/" rel="nofollow">jsfiddle here</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload