<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Document</title> <style type="text/css"> body{margin: 0;padding: 0;} #div1{ background:red; width: 400px; height: 400px; filter: alpha(opacity:30); opacity: 0.3; } </style> </head> <body> <!-- Javascript --> <script type="text/javascript"> window.onload = function(){ var oDiv = document.getElementById('div1'); oDiv.onmouseover = function(){ starMove(0.1,1) } oDiv.onmouseout = function(){ starMove(-0.1,0.3) } } var timer = null; var opacity = 0.3; function starMove(speed,ita){ clearInterval(timer); var oDiv = document.getElementById('div1'); timer=setInterval(function(){ if (oDiv.style.opacity==ita) { clearInterval(timer); } else{ opacity = opacity + speed; oDiv.style.opacity = opacity + speed; } },100) } </script> <!-- html --> <div id="div1"></div> </body> </html>
以上代码没有设置filter:alpha(opacity)但是兼容自带的ie9,百度有人说opacity通用,那么opacity的兼容性到底如何;是否只是兼容高版本ie还是真的通用,以及filter:alpha(opacity)的设置是否有必要
我用IE兼容软件测试了一下,filter:alpha(opacity)必须要有的,不然低版本的IE是没有效果的
opacity属性ie9+支持
filter属性ie6~9支持