<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>JavaScript 高级课程之淡出淡入CSS filter等属性</title>
<style>
#img1 {filter:alpha(opacity:30); opacity:0.3;}
</style>
<script>
var alpha = 30;
window.onload = function(){
var oImg = document.getElementById('img1');
oImg.onmouseover = function(){
fn(100,2);
}
oImg.onmouseout = function(){
fn(30,-2);
}
}
var Timer = null;
function fn(value,iSpeed){
var oImg = document.getElementById('img1');
clearInterval(Timer);
Timer = setInterval(function(){
if(alpha != value){
alpha += iSpeed;
document.title = alpha;
//IE
oImg.style.filter = 'alpha(opacity:'+ alpha +')';
//FF 比如50/100=0.5
oImg.style.opacity = alpha/100;
}else{
clearInterval(Timer);
}
},20);
}
</script>
</head>
<body>
<img src="aa.jpg" id="img1" />
</body>
</html>
JavaScript 高级课程之淡出淡入CSS filter等属性
最新推荐文章于 2025-08-18 15:35:58 发布