jQuery的:我可以动画的位置:绝对位置:相对?

编程入门 行业动态 更新时间:2024-10-28 08:30:10
本文介绍了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的:我可以动画的位置:绝对位置:相对?

本文发布于:2023-07-20 05:11:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1164516.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:位置   动画   jQuery

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!