jQuery折叠褪色div和展开动画问题
我正在尝试将图像动画化为 div 的完整宽度和高度,它与我期望的左上角图像一起使用,但其他图像将图像移动到左上角,然后对其进行动画处理
有没有办法让兄弟姐妹淡出,然后从当前位置为图像设置动画?
谢谢
解决方案
为了获得在所有浏览器中都有效的我想要的效果,我这样做了jsFiddle
感谢 iWasRobbed 帮助解决问题
I'm trying to animate an image to the full width and height of a div it works with the top left image as i'd expect but the others it moves the image to the top left and then animates it
Is there a way to fade the siblings out and then animate the image from its current position?
Thanks
SOLUTION
To get my desired effect which works in all browsers I did this jsFiddle
Thanks to iWasRobbed for helping with the solution
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这绝对是可能的,只是不能使用
fadeIn
或fadeOut
函数。相反,您必须为绝对定位元素设置不透明度动画。如果您尝试使用fadeIn
或fadeOut
那么它不会执行任何操作。这是一个 jfiddle 版本,它在 jQuery 1.5.0 中工作(为看不到损坏图像符号的 Firefox 用户添加了 Orbling 图像):
It definitely is possible, just not with the
fadeIn
orfadeOut
functions. Instead, you have to animate opacity on absolutely positioned elements. If you try and usefadeIn
orfadeOut
then it does nothing.Here is a jfiddle version with jQuery 1.5.0 where it works (added Orbling's images for Firefox users who can't see a broken image symbol): http://jsfiddle.net/iwasrobbed/qPkr5/1/
是啊,决定玩玩这个,可不容易实现。
这是我到目前为止所得到的,仍然有很多问题,但这是一个起点。
演示:http://jsfiddle.net/NzcZH/
初始布局
淡入淡出
增长
Fullsize
本质上,每个图像都挂接到
.mouseenter()
(文档) /.mouseleave()
(docs) 事件,并尝试激活所需的图像,或根据需要停用它,如果某些事情已经发生,则会创建一个原始队列(需要修复)。激活就是你的方式,通过一些修改,它会淡出不透明度,然后增长活动图像。停用则相反,将活动图像缩小回原始图像,然后淡入(通过不透明度)。
对模型的更改主要是执行此类动画所需的 HTML/CSS。
如果您直接使用
.fadeIn()
(docs) /.fadeOut()
(文档) 例程,这些.hide()
(docs) 最后的图像(display: none;)
,这会将它们从场景中删除,并最终将未褪色的活动图像移动到顶角,这破坏动画。使用不透明度和图像的绝对定位来将它们固定到位效果更好。您可以让它们淡出和隐藏,并在动画之前重置坐标,但如果您想要任何重叠,那就不好了。理想情况下,应该更改图像上的 z-index 以使活动项目保持在顶部,这将允许并行淡入淡出和增长,目前它是上演的。
[我正在使用
.data()
(docs) 例程来存储当前状态而不是一堆变量,有点整洁。]HTML 结构
CSS
jQuery 代码
Right, decided to have a play with this, it is not at all easy to achieve.
This is as far as I have got so far, still quite bugged, but it's a starting point.
Demo: http://jsfiddle.net/NzcZH/
Initial Layout
Fading
Growing
Fullsize
Essentially, each image is hooked in to the
.mouseenter()
(docs) /.mouseleave()
(docs) events, and an attempt is made to activate the required image, or deactivate it as required, if something is already going on, a primitive queue is created (which needs fixing).Activation is how you had it, with a couple of modifications, it fades the opacity out, then grows the active image. Deactivation is the reverse, shrink the active image back to the original, and then fade in (via opacity).
The changes to the model are mainly HTML/CSS necessities to do this sort of animation.
If you use straight
.fadeIn()
(docs) /.fadeOut()
(docs) routines, these.hide()
(docs) the images(display: none;)
at the end, which removes them from the scene and ends up moving the non-faded, active image to the top corner, which breaks the animation. Using opacity instead and absolute positioning of the images to hold them in place works better. You could let them fade and hide, and reset the coordinates before animation instead, but that is no good if you wanted any overlap.Ideally, the
z-index
should be altered on the images to keep the active item on top, this would allow parallel fading and growing, at present it is staged.[I'm using the
.data()
(docs) routine to store current state rather than a load of variables, bit neater.]HTML Structure
CSS
jQuery Code