Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/400.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何将动画添加到此页边距顶部值更改?_Javascript_Jquery_Click_Jquery Animate - Fatal编程技术网

Javascript 如何将动画添加到此页边距顶部值更改?

Javascript 如何将动画添加到此页边距顶部值更改?,javascript,jquery,click,jquery-animate,Javascript,Jquery,Click,Jquery Animate,我有一个基本的小js/jquery函数,但我似乎无法获得修改身体“边距顶部”的动画效果-我需要3em的当前值将动画设置为0em。以下是我的功能: $(".notify-close").click(function () { $('#notify-container').css('display', 'none'); $('body').css("margin-top", "0em"); }); 我搞不清楚的一个部分是如何删除像素(在这种情况下是EM)-例如,这里有一个想法,关于向当前边

我有一个基本的小js/jquery函数,但我似乎无法获得修改身体“边距顶部”的动画效果-我需要3em的当前值将动画设置为0em。以下是我的功能:

$(".notify-close").click(function () {
  $('#notify-container').css('display', 'none');
  $('body').css("margin-top", "0em");
});
我搞不清楚的一个部分是如何删除像素(在这种情况下是EM)-例如,这里有一个想法,关于向当前边距顶部添加50个像素,使用“+=50”值,但是在EM中删除与此等效的是什么?比如“-3EM”?:

你试过这个吗

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

我刚刚使用了这个脚本-在更改主体边距顶部值的EM值方面,它不是100%动画化的,但它现在是一个基本修复:

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

$(“.notify close”)。单击(函数(){
$('#notify container').css('display','none');
$('body').css(“页边空白顶部”,“0”);
});         
$("body").animate({
    margin-top: "50px"
  }, 1500 );
<script>
    $(".notify-close").click(function () {
        $('#notify-container').css('display', 'none');
        $('body').css("margin-top", "0");
    });         
</script>