JavaScript 收缩/增长循环过渡
我的第一个问题在这里。 :)
我正在寻找两个图像之间的过渡,其中图像首先缩小为圆形,然后圆圈再次增长,包含另一个图像。这很难解释,而且我可能用错了词,因为我在 Interwebz 上找不到任何相关内容。
我说的是像《疯狂卡通》结局这样的效果。 http://www.youtube.com/watch?v=ZuYIq-J5l9I
缩小到-黑色,可以用 JavaScript/JQuery 完成吗?
My first question here. :)
I'm looking for a transitions between two images where the image first shrinks in a circle shape and then the circle grows again containing the other image. It's hard to explain, and I may be using the wrong words, because I can't find anything about it on the Interwebz.
I'm talking about an effect like the Loony Toons ending.
http://www.youtube.com/watch?v=ZuYIq-J5l9I
That shrinking-to-black, can it be done in JavaScript/JQuery?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
TL:DR
- Cross-browser: [**See a working demo
here**](http://jsfiddle.net/lthibodeaux/8DSjz/).
Well, mostly working... and
cross-browser. Could do worse. ;]
- Purely CSS3 Solution: [**See a working demo
here**](http://jsfiddle.net/lthibodeaux/8DSjz/16/)
我该如何开始描述这个呢?如果 CSS 2 剪辑标准支持除“矩形”值之外的任何内容(即“圆”或“椭圆”),那就容易多了,但是……因为这不存在,所以我已经尽力拼凑一些东西在一起就可以完成你所要求的事情。需要注意的地方有很多。一是,如果您希望图片剪辑到背景上,这仅适用于具有纯色背景的内容。另一个问题是,虽然我尝试考虑跨浏览器的 CSS 更新时间,但渲染仍然不“完美”。我最初的方法是简单地对要替换的图像上的剪辑进行动画处理,但这不起作用,因为通过我找到的插件中的缓动功能对剪辑进行了更新。最终的方法如下。
方法
这个概念是将图像设置为容器的
background-image
属性,例如带有的
,以及容器的center center
的背景位置position
到relative
,或任何非静态的内容。接下来是生成剪辑元素作为容器的子元素。第一个是背景颜色的position:absolute
剪贴圆图像,透明 PNG 或 GIF(我更喜欢前者),接下来的四个是 div,也带有absolute< /code> 位置,每个位置的
left
、right
、top
和bottom
属性均设置为 0他们将剪裁各自的侧面。这个想法是对剪切圆图像的top
、left
、width
和height
进行动画处理并同步使用 .animate() 调用的步骤回调选项将剪辑 div 的宽度和高度与当前left
和top
值进行匹配。在动画之间,您将容器的background-image
更改为新图像,然后以相反的方向启动动画。这需要在 IE7、8 和 Webkit 浏览器中进行一些处理,因为动画在 Firefox 和 IE9 中剪辑得更加干净。这将是您将在工作演示中看到的
调整
变量。示例代码如下:
标记
CSS
脚本
编辑:
CSS3 解决方案 当不太关心
跨浏览器兼容性时,CSS3 是一个选择(尽管我可能建议看看新的 HTML5 Canvas 可以为此类动画做些什么)。有几点需要注意:
该方法内嵌注释如下:
标记
CSS
脚本
演示位于此处。TL:DR
- Cross-browser: [**See a working demo
here**](http://jsfiddle.net/lthibodeaux/8DSjz/).
Well, mostly working... and
cross-browser. Could do worse. ;]
- Purely CSS3 Solution: [**See a working demo
here**](http://jsfiddle.net/lthibodeaux/8DSjz/16/)
How do I even begin to describe this one? It would be a lot easier if the CSS 2 clip standard supported anything besides a "rect" value, namely a "circle" or "ellipse" but... since that doesn't exist, I've done my best to piece something together that will do what you're asking. The caveats are many. One is that this is only going to work on something with a solid color background in the event you wanted the picture to clip to the background. Another is that while I've tried to account for the CSS update timing across browsers, the rendering still isn't "perfect." My initial approach was to simply animate the clip on the image that was getting replaced, but that didn't work due to the way updates were made to the clipping via the easing function in the plugin I located. The final approach is below.
The Approach
The concept is to set the image as a
background-image
property of a container like a<div>
with abackground-position
ofcenter center
, and theposition
of the container torelative
, or anything non-static. The next is to generate the clipping elements as children of the container. The first is aposition: absolute
clipping circle image of the color of your background, either transparent PNG or GIF (I prefer the former), and the next four are divs, also withabsolute
positions that haveleft
,right
,top
, andbottom
attributes set to 0 for each of the respective sides they will clip. The idea is to animate thetop
,left
,width
, andheight
of the clipping circle image and synch up the width and height of the clipping divs using the step callback option of the .animate() call by matching them to the currentleft
andtop
values. Between animations, you change thebackground-image
of the container to the new image and then start the animation back in the opposite direction.This required a little finessing in IE7, 8, and Webkit browsers as the animation clipped much more cleanly in Firefox and IE9. This would be the
adjust
variable you'll see in the working demo.The sample code is below:
The Markup
The CSS
The Script
EDIT:
The CSS3 Solution
When cross-browser compatibility is less of a concern, CSS3 is an option (although I'd probably suggest seeing what can be done with the new HTML5 Canvas for this kind of animation). There are a couple things to note:
The method is commented inline below:
The Markup
The CSS
The Script
Again, the demo is located here.我遇到了这个,我希望它很有趣:http://www.netzgesta.de/transm/。我认为带有一个圆圈的过渡
circles_out
可以完成这项工作。I came this across, I hope it is interesting: http://www.netzgesta.de/transm/. The transition
circles_out
with one circle could do the job I think.干得好。 http://jquery.malsup.com/cycle/ 查看缩放效果。可以用圆圈部分解决一些问题。
Here you go. http://jquery.malsup.com/cycle/ Check out the zoom. Something can be worked out with the circle part.
我尝试了更多,并提出了使用
元素的想法。
请在以下位置查看结果:http://jsfiddle.net/3MG8e/2/。
I tried some more and came up with the idea of using a
<canvas>
element.Please see the result at: http://jsfiddle.net/3MG8e/2/.