我正在尝试制作一个网页,其中图像的背景颜色会逐渐改变颜色。我知道如何在 Javascript 中更改某些东西的背景颜色,但我不知道如何“动画化”它可以这么说(不使用 Flash)。
最佳答案
您可以使用 CSS 过渡来获得这种效果。只需将该 css 代码添加到从 js 更改的元素中:
-webkit-transition: all 1s ease-in-out;
-moz-transition: all 1s ease-in-out;
-o-transition: all 1s ease-in-out;
-ms-transition: all 1s ease-in-out;
transition: all 1s ease-in-out;
在 css 上,每次更改任何样式值时,都会以 1 秒的速度从当前值动画更改为新值。
它只适用于现代浏览器。看一个例子:click
关于javascript - 如何让背景逐渐变色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9369365/