0

我想让一个透明背景的 div 平滑地改变颜色,问题是我需要在 div 上有一些不透明的内容。

我发现这是为了改变颜色

<head>
<script 
   src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js">
</script>
<script type="text/javascript">
$(document).ready(function() {
setInterval ( "spectrum()", 1000 );
   }); 

function spectrum(){
var hue = 'rgb(' + (Math.floor(Math.random() * 256)) + ',' + 
   (Math.floor(Math.random() * 256)) + ',' + 
   (Math.floor(Math.random() * 256)) + ')';
$('body').css( { backgroundColor: hue });

}

</script>
</head>
</body>
</html>

但我不知道如何在其中添加透明度。

我想要的另一件事是通过移动光标来更改颜色。我认为应该可以将它与 jQuery.mousemove()函数结合起来。

非常感谢

4

3 回答 3

0

使用 CSS 进行过渡:

body{
  -webkit-transition: background-color 1s linear;
}

实时代码:http: //jsbin.com/oqesub/1/edit

于 2013-03-17T19:00:47.127 回答
0

更改rgbrgba

rgba(red,green,blue,opacity)
于 2013-03-17T19:00:58.560 回答
0

半透明颜色的格式是rgba( R, G, B, A), 其中R, G,B是您已经拥有的,并且A是介于 0(完全透明)和 1(完全不透明)之间的数字。由您决定您需要的确切数字是多少。

于 2013-03-17T19:01:09.807 回答