且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何让背景逐渐改变颜色?

更新时间:2023-01-27 12:05:53

您可以使用CSS转换来获得该效果。只需将css代码添加到从js更改的元素中:

You can use CSS transitions to get that effect. Just add that css code into the element that is changed from 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上使用该值时,该更改将从当前值更新为新值1s。

With that on css each time any style value is being changed that change is animated from current to new value by 1s.

它仅适用于现代浏览器。查看示例:点击

It works only on modern browsers. See an example: click