动画颜色变化过渡
每当使用 css 或任何东西时,我们都会更改颜色,例如背景、颜色、边框颜色等。有没有一种方法可以为正常颜色和悬停状态颜色之间的过渡设置动画?
我想说的是颜色,可以说立即从白色变为黑色。我想要过渡阶段,就像白色和黑色之间的所有灰度级一样。对于颜色,如果一种颜色淡入另一种颜色,则可以通过淡入淡出效果来实现。中间的颜色被掩盖了。
有办法实现这一点吗?
Whenever with css or anything we change colors like backgrounds, color, border color etc. Is there a way we can animate the transition between normal and hover state colors?
What I want to say is the colors, lets say change instantly from white to black. I want the transition stages like all the gray-scale in between white and black. With colors this can be attained by fade effect if one colors fades into another. The in between colors are covered up.
Is there a way to achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这可以通过 CSS3 来完成,尽管它还不是完全跨浏览器的。 http://www.the-art-of-web.com/ css/css-animation/
或者你可以使用 jQuery .animate(); http://api.jquery.com/animate/
This can be done with CSS3, although it's not completely cross-browser as of yet. http://www.the-art-of-web.com/css/css-animation/
Alternatively you could use jQuery .animate(); http://api.jquery.com/animate/
听起来像是 jQuery 的工作 - 特别是 animate() 方法:
http://api.jquery.com/动画/
Sounds like a job for jQuery - specifically, for the animate() method:
http://api.jquery.com/animate/
是否可以?是的,
这怎么可能? javascript
X3Maverick 有一个很好的答案(抱歉,没有投票),但您也可以尝试制作一个计时器来相应地调整颜色,
这将允许您准确指定您想要的颜色以及顺序。请仅将您的力量用于善良或伟大的目的。闪烁的颜色和闪烁的文字会导致癫痫发作,因此不受欢迎。
jQuery 现在有一个官方的彩色动画插件:
http://docs.jquery.com/Release:jQuery_1.2/Effects#Color_Animations
is it possible? yes
how is it possible? javascript
X3Maverick has a good answer (out of up-votes, sorry), but you could also try making a timer to adjust the colors accordingly
this would allow you to specify exactly what colors you want and in what order. Please only use your powers for good or for awesome. Flashing colors and blinking text cause seizures and are not appreciated.
jQuery now has an official color animation plugin:
http://docs.jquery.com/Release:jQuery_1.2/Effects#Color_Animations
您无法使用 jQuery 直接设置颜色动画,因为“颜色”不是数字 CSS 属性。
但是您可以这样做:让元素 A 的样式设置为反映非悬停状态,让元素 B 的样式设置为反映悬停状态(不透明度设置为 0 除外)。然后将元素 B 绝对定位在元素 A 的正上方。然后使用 jQuery fadeIn() 和 fadeOut() 方法更改悬停时元素 B 的不透明度。
You can't directly animate color using jQuery since "color" is not a numeric CSS property.
But you can do something like this: Let element A be styled to reflect the non-hover state, and let element B be styled to reflect the hover state except with opacity set to 0. Then absolutely position element B directly over element A. Then use the jQuery fadeIn() and fadeOut() methods to change the opacity of element B on hover.