Js动画-改变透明度(二)
程序员文章站
2024-03-24 08:28:22
...
JS改变透明度
//Description:鼠标移入颜色变深,移出变淡
var timer=null;
var alpha=30;
function startMove(target)
{
var Div=document.getElementById("div1");
clearInterval(timer);
timer=setInterval
(
function()
{
var speed=0;
if(alpha>target)
{
speed=-10
}
else
{
speed=10;
}
if(alpha==target)
{
clearInterval(timer);
}
else
{
alpha+=speed;
Div.style.filter='alpha(opacity:)'+alpha+')';
Div.style.opacity=alpha/100;
}
},30
)
}
了解参数:
- opacity:0.3; filter:alpha(opacity:30) //设置不透明度(opacity要放前面)