利用linear-gradient不停的改变背景颜色,实现动态效果??????
代码大致如下,循环的地方有问题,找不出来,各位大侠帮忙看看,谢谢了!对不起,没有分了。。。程序代码:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <script> window.onload=function a(){ var setgrad1=document.getElementById("grad1"); var i=0; for(i;i<=360;i++){ setgrad1.style.background="linear-gradient('+i+'deg, red, blue)"; } } var t=window.setTimeout("a()",500); window.clearTimeout(t); </script> <style> #grad2 { height: 100px; background: linear-gradient(90deg, red, blue); /* 标准的语法(必须放在最后) */ } #grad3 { height: 100px; background: -webkit-linear-gradient(180deg, red, blue); /* Safari 5.1 - 6.0 */ background: -o-linear-gradient(180deg, red, blue); /* Opera 11.1 - 12.0 */ background: -moz-linear-gradient(180deg, red, blue); /* Firefox 3.6 - 15 */ background: linear-gradient(180deg, red, blue); /* 标准的语法(必须放在最后) */ } #grad4 { height: 100px; background: -webkit-linear-gradient(-90deg, red, blue); /* Safari 5.1 - 6.0 */ background: -o-linear-gradient(-90deg, red, blue); /* Opera 11.1 - 12.0 */ background: -moz-linear-gradient(-90deg, red, blue); /* Firefox 3.6 - 15 */ background: linear-gradient(-90deg, red, blue); /* 标准的语法(必须放在最后) */ } </style> </head> <body> <h3>线性渐变 - 使用不同的角度</h3> <div id="grad1" style="color:white;text-align:center;height: 100px;">0deg</div><br> <div id="grad2" style="color:white;text-align:center;">90deg</div><br> <div id="grad3" style="color:white;text-align:center;">180deg</div><br> <div id="grad4" style="color:white;text-align:center;">-90deg</div> <p><strong>注意:</strong> Internet Explorer 9 及之前的版本不支持渐变。</p> </body> </html>