How do I stop a jquery animation based on CSS values?

Posted by kevn on Stack Overflow See other posts from Stack Overflow or by kevn
Published on 2010-05-31T18:08:27Z Indexed on 2010/05/31 18:13 UTC
Read the original article Hit count: 176

Filed under:
|
|

So, I have two divs: #div1 and #div2. I want '#div2' to disappear when '#div1' has the CSS value: top = 0px.

Here is the CSS:

#div1 {
    top: 0px;
}
#div2 {
    display: block;
} 
if ( $('#div1').css('top') == '0px' ) {
    $("#div2").hide();
} else {
    $("div2").fadeIn();
}
$("div2").click(function(){
        $("#div1").animate({top:"+=315px"}, "slow");
});

The problem I am running into is that I'm changing that CSS value (for #div1) via Javascript and for this reason, my js doesn't acknowledge the change and doesn't make the div disappear (I think). Is there any way to make #div2 disappear when #div1's CSS property top = 0 and reappear whenever it is changed? Or is there a better way to implement this?

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about css