jQuery的:我可以动画的位置:绝对位置:相对? [英] jquery: can i animate the position:absolute to position:relative?
本文介绍了jQuery的:我可以动画的位置:绝对位置:相对?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一堆图像的位置绝对正确,我希望能够单击一个按钮并使它们全部动画化,如果它们具有以下位置,它们通常会出现在页面上:
i have a bunch of images that are positioned absolutely, i want to be able to click a button and have them all animate to where they would normally be on the page if they had the position: relative.
那么在jquery中甚至可以从position:absolute动画到position:relative吗?
so is it even possible to animate from position:absolute to position:relative in jquery?
这就是我所拥有的:
$(".change_layout").click(function(){
$(".book_img").animate({position:'relative', top:'0px', left:'0px'}, 1000)
})
推荐答案
不,您不能直接为其设置动画,但是可以找到端点并为其设置动画.当动画移至static
位置时,类似的事情可能会起作用:
No, you cannot animate it directly but you can find out the end point and animate the position there. Something like this might work when animation to the static
position:
$('img.foo').each(function() {
var el = $(this);
// Make it static
el.css({
visibility: 'hidden', // Hide it so the position change isn't visible
position: 'static'
});
// Get the static position
var end = el.position();
// Turn it back to absolute
el.css({
visibility: 'visible', // Show it
position: 'absolute'
}).animate({ // Animate to the static position
top: end.top,
left: end.left
}, function() { // Make it static
$(this).css('position', 'static');
});
});
有点黑,但应该可以.
这篇关于jQuery的:我可以动画的位置:绝对位置:相对?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文