How can I create a looping fade-in/out image effect using CSS 3 transitions?

孤街浪徒 提交于 2019-12-01 03:22:09

问题


I’m trying to create a looping fade in/out effect for an image. It’s working in Chrome, but it doesn’t work in Firefox.

Here’s the code: http://jsfiddle.net/FTLJA/254/

(I did make it work with jQuery but that made the browser slow and flickery on Android phones, so I’m trying CSS instead.)

Thanks for any help.

Update: fixed.. please check the link again


回答1:


Well, if ypu're only setting the WebKit properties (only @-webkit-keyframes and only -webkit-animation-...), then of course it will work only in WebKit and not in Firefox - add them with -moz prefix as well. Also remove the quotes around 'blink' to leave it just... blink and it works http://jsfiddle.net/FTLJA/261/




回答2:


Ah yes — this shows a difference between CSS transitions and CSS animations.

CSS animations run once you’ve applied -webkit-animation-name to an element, i.e. they can run entirely from CSS.

Transitions, on the other hand, only run when you change the CSS property that they apply to. You can either do this via CSS pseudo-classes like :hover, or via JavaScript.

So, in order to make your transition work in browsers that don’t support -webkit-animation, you’ll need to run some JavaScript that changes the opacity of the image once a second — setInterval is your friend here.

(Note that your JavaScript won’t carry out the animation, it’ll just switch opacity straight from 1 to 0 and back again every second. The CSS transition will animate this change for you.)



来源:https://stackoverflow.com/questions/11578800/how-can-i-create-a-looping-fade-in-out-image-effect-using-css-3-transitions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!