如何让背景逐渐改变颜色? [英] How to make background gradually change colors?

查看:94
本文介绍了如何让背景逐渐改变颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一个网页,其中图像的背景颜色会逐渐改变颜色。我知道如何在Javascript中更改某些内容的背景颜色,但我不知道如何动画它可以这么说(不使用Flash)。

I'm trying to make a web page where the background color of an image gradually changes colors. I know how to change the background color of something in Javascript, but I don't know how to "animate" it so to speak (without using Flash).

推荐答案

您可以使用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

这篇关于如何让背景逐渐改变颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆