Javascript jQuery Animate 顶部(从下到上)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8026900/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jQuery Animate top (From bottom to top)
提问by jQuerybeast
I am trying to animate a Div a top:275
.
我正在尝试为 Div a 设置动画top:275
。
I tried .animate( {marginTop: -820 }
but on each screen it ends up to a different position. . .
我试过了,.animate( {marginTop: -820 }
但在每个屏幕上它最终都会出现在不同的位置。. .
So I changed the marginTop to .animate( {top: 275}
but the div comes from the top to down (slidedown). Note that, so I can use the animate:top
I had to set the div to position:absolute
during the animation. . .
所以我将 marginTop 更改为.animate( {top: 275}
但 div 从上到下(幻灯片)。请注意,因此我可以使用animate:top
我必须position:absolute
在动画期间将div 设置为。. .
Is there any hackyway to make the top come from the bottom up or make the marginTop have the same distance from the top on each screen resolution ?( I assume margintop can't be solved since im setting margin top to -820 in order to get at a point of top:275, therefore screens smaller than 1200px height, the div will go much higher...)
是否有任何技巧可以使顶部从底部向上或使 marginTop 在每个屏幕分辨率上与顶部的距离相同?(我认为 margintop 无法解决,因为我将 margin top 设置为 -820 以获得 top:275 的点,因此屏幕高度小于 1200px,div 会高得多......)
Here is my code:
这是我的代码:
$("#features").fadeIn()
.css({
position: 'absolute'
}).animate({
top: '275'
}, function() { //callback });
回答by jQuerybeast
Ah Found it!!
啊找到了!!
$("#features").fadeIn()
.css({top:1000,position:'absolute'})
.animate({top:275}, 800, function() {
//callback
});
So basically I've set the top from css at the very end to 1000, then animated it to 275 which is up...
所以基本上我已经在最后将 css 的顶部设置为 1000,然后将其动画设置为 275,这是向上的...
回答by Mani_k
$( '#features' ).show()
.css( {'opacity': 0, 'bottom': '-100px' } )
.animate( { 'opacity': '1', 'bottom' : 0 }, 1000 );