开发者

How to add an animation to this margin-top value change?

I've got a basic little js/jquery function, but I can't seem to get the animation work for a change to the Body's "margin-top" - I need the current value of 3em to animate down to 0em. Here's my function:

$(".notify-close").click(function () {
  $('#notify-container').css('display', 'none');
  $('body').css("margin-top", "0em");
});

One part I can't figure out is how to remove pixels (or EM in this case) - for example, here's an idea regarding adding 50 pixels to a current margin-开发者_C百科top, with a "+=50" value, but what's the REMOVAL equivalent to this in EM? Like "-3EM" ????:

$("body").animate({
    margin-top: "+=50"
  }, 1500 );


Did you try this?

$("body").animate({
    margin-top: "-=50em"
}, 1500 );


$("body").animate({
    margin-top: "50px"
  }, 1500 );


I just used this script - it's not 100% animated in regards to changing the EM value for the body's margin-top value, but its a basic fix for now:

<script>
    $(".notify-close").click(function () {
        $('#notify-container').css('display', 'none');
        $('body').css("margin-top", "0");
    });         
</script>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜