views:

1210

answers:

6

I am trying to make a sort of "scales" look, where two divs will slowly animate up and down like being weighed on a scale. I could use some help with the functions though please, I can not get two to animate simultaneously on page load, and I need them to go up, then back down, then up, etc... Make sense? Here is what I have so far, I am kinda new to jquery obviously, :) Thanks for any help!

<style type='text/css'>
  body {
    background: #262626;    
  }
  .main 
  {
    margin: 20px auto;
    position:relative;    
    height:400px;    
    width:300px; 
  } 
  .content 
  {
    float: left;
    position:absolute; 
    bottom: 10px;   
    left: 100px;
    height:40px;    
    width: 100px;    
  } 
  .content2 
  {
    float: left;
    position:absolute; 
    top: 10px;   
    left: 100px;
    height:40px;    
    width: 100px;    
  }
</style>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript" charset="utf-8"></script>

<script type="text/javascript">
    $(document).ready(function() {
        $(".content").animate({top:'10px'},{ queue:true, duration:3000 }),  
        $(".content2").animate({bottom:'10px'},{ queue:true, duration:3000 });    
    });
</script>

<div class="main">
    <div class="content">
        <img src="pixel.png" alt="" />
    </div>
    <div class="content2">
        <img src="functional.png" alt="" />
    </div>
</div>
+1  A: 

If you want them animated simultaneously, you should set queue to false.

seth
I set the queue to false on them but nothing changed...
thatryan
A: 

Wanted to clarify a few pieces, it works kinda. :) Jquery is working, but when I load the page, all that happens is the div class content div, the first one, goes from bottom to top. The second div does nothing...

thatryan
Don't use answers to do followups. instead, edit your original post or post a comment on the original post.
Soviut
Sorry about that :(
thatryan
A: 

I think there should be a semicolon instead of a comma at the end of this line:

$(".content").animate({top:'10px'},{ queue:true, duration:3000 }),

That would explain why the next line is not being called.

Chris
still nothing, only one is animating...
thatryan
+1  A: 

document.ready does not wait for images to download. So use window.onload instead. And you should not be queueing if you want them to animate simultaneously. Also, I think in your animation you need to reset the top/bottom values respectively, so they don't interfere with each other...

$(window).load(function() {
  $(".content").animate({top:'10px', bottom:0}, 3000);
  $(".content2").animate({bottom:'10px', top:0}, 3000);
});
Josh Stodola
A: 

I wanted to show you guys what I came up with, with help from various sources. This give the "teeter totter" effect on page load which I was going for, but my question is, is it too "brute force" ? Is there a better, smoother way to do this?

And I posted this as an answer because It is my answer so far, I hope that is ok.

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

$("#box1").animate({top:'+=150px'},3000  );
$("#box2").animate({top:'-=150px'},3000 );

$("#box1").animate({top:'-=150px'},3000  );
$("#box2").animate({top:'+=150px'},3000 );

$("#box1").animate({top:'+=100px'},4000  );
$("#box2").animate({top:'-=100px'},4000 );

$("#box1").animate({top:'-=100px'},4000 );
$("#box2").animate({top:'+=100px'},4000 );

$("#box1").animate({top:'+=50px'},5000  );
$("#box2").animate({top:'-=50px'},5000 );

$("#box1").animate({top:'-=20px'},5000 );
$("#box2").animate({top:'+=20px'},5000 );

});
</script>
thatryan
A: 

nice website, i think the animation is a bit too quick though, as dont have enough time to read text needs longer pause.

guest