CSS3 过渡链接
什么是语法上干净的解决方案来在单个元素上逐个运行一系列单独的 CSS3 转换?示例:
- 将 left 设置为 10px,不透明度为 1 到 200ms
- 将 left 设置为 30px 到 500ms
- 将 left 设置为 50px,不透明度为 0 到 200ms
这可以在没有 JavaScript 的情况下完成吗?如果没有,如何用 JavaScript 干净地编码?
What is a syntactically clean solution to run a chain of individual CSS3 transitions on a single element, one by one? An example:
- set left to 10px and opacity to 1 through 200ms
- set left to 30px through 500ms
- set left to 50px and opacity to 0 through 200ms
Can this be done without JavaScript? If not, how to code it cleanly with JavaScript?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我相信您想要一个 CSS3 动画,您可以在动画中的不同点定义 CSS 样式,然后浏览器为您进行补间。以下是对其的一个描述:http://css3.bradshawenterprises.com/animations/。
您必须检查目标浏览器的浏览器支持情况。
这是一个在 Chrome 中运行的演示。动画是纯CSS3,我只使用Javascript来启动和重置动画:
http://jsfiddle.net/jfriend00 /fhemr/
可以修改 CSS 以使其在 Firefox 5+ 中也能工作。
I believe you want a CSS3 animation where you define the CSS styles at different points in the animation and the browser does the tweening for you. Here's one description of it: http://css3.bradshawenterprises.com/animations/.
You will have to check on browser support for your targeted browsers.
Here's a demo that works in Chrome. The animation is pure CSS3, I only use Javascript to initiate and reset the animation:
http://jsfiddle.net/jfriend00/fhemr/
The CSS could be modified to make it work in Firefox 5+ also.
在纯 CSS 中,这可以通过 transition-delay 属性来完成,有了它你可以延迟第二次和第三次转换。
我个人更喜欢 JS 解决方案。可以使用超时或“transitioned”事件来实现此目的。
我还建议 script.aculo.us (或 beta v2:scripty2),它是专门为使此类事情的编程变得高效和简单而设计的。
In pure CSS this can be done with the transition-delay property, with it you can delay the second and third transition.
I personally would like a JS solution better. timeouts or the "transitioned" event can be used to achieve this.
I would also suggest the script.aculo.us (or the beta v2: scripty2), it is especially designed to make programming these kinds of things efficient and easy.