js动态改变 style 内容
发布时间:2017年3月1日 作者:未知 查看次数:1419
自:http://bbs.blueidea.com/thread-3109058-1-1.html <!DOCTYPE html> <html> <style> div.a { animation: myfirst 1s; -webkit-animation: myfirst 1s; } </style> <style id=dynamic></style> <body> <div id='a'> 123 </div> <script> var colors = ['red','yellow','blue','green'] window.setTimeout(function (){ var color = colors.shift() console.log(color) if (!color) return var style = document.getElementById("dynamic") style.innerHTML = '@-webkit-keyframes myfirst{50% {background: '+color+';} }\n' + '@keyframes myfirst {50% {background: '+color+';}}' var a = document.getElementById('a') a.className = 'a' window.setTimeout(function(){ a.className = '' },1000) window.setTimeout(arguments.callee,1500) },1000) </script> </body> </html>
|
|
|