使用 jquery 移动元素
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4998757/
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
moving elements with jquery
提问by med
How can I use jQuery to move an element from:
如何使用 jQuery 从以下位置移动元素:
position: absolute;
left: 169px;
top: 182px;
to:
到:
position: absolute;
left: 169px;
top: 230px;
with clear moving so not just css, it has to be moving.
清晰的移动所以不仅仅是CSS,它必须是移动的。
Thanks.
谢谢。
回答by simshaun
http://api.jquery.com/animate/
http://api.jquery.com/animate/
Demo: http://jsfiddle.net/pHwMK/
演示:http: //jsfiddle.net/pHwMK/
JS:
JS:
$(function() {
$("div.ele").animate({ top: '230px' });
});
回答by David Tang
What you mean is animation? Assuming an element with id="someElement"
already has position:absolute
and left:169px
, then:
你说的是动画?假设一个元素id="someElement"
已经有position:absolute
and left:169px
,那么:
$('#someElement').animate({top: 230});
If you need to set the initial CSS on the element before animating it, then have an extra .css()
call before .animate()
:
如果您需要在设置动画之前在元素上设置初始 CSS,请在之前进行额外.css()
调用.animate()
:
$('#someElement').css({
position: 'absolute',
left: 169,
top: 182
}).animate({top: 230});