为了账号安全,请及时绑定邮箱和手机立即绑定

JavaScript做透明度改变,每次刷新后第一画面闪一下,然后正常?

JavaScript做透明度改变,每次刷新后第一画面闪一下,然后正常?

qq_启啟啓_03860251 2016-10-11 09:22:10
<!DOCTYPE html><html><head><meta charset="UTF-8"><title>透明度</title><style type="text/css">*{padding: 0;margin: 0;}#color{width: 250px;height: 250px;margin: 80px auto;background-color: red;filter: alphal(opcity=100);opacity: 1;}</style></head><body><div id="color"></div><script type="text/javascript">window.onload = function(){var col = document.getElementById("color");col.onmouseover = function(){ms(col,30);}col.onmouseout = function(){ms(col,100);}}var timer;//var opac =100;function ms(obj,itar){var opac = obj.style.opacity*100,speed = 0;if(opac < itar){speed = 10;}else{speed = -10;}clearInterval(obj.timer);obj.timer = setInterval(function(){if(opac == itar){clearInterval(obj.timer);}else{opac += speed;obj.style.filter = "alphal(opcity="+ opac +")";obj.style.opacity = opac/100;}},50);}</script></body></html>若采用全局常数则不会出现问题
查看完整描述

3 回答

?
努力赚钱

TA贡献5条经验 获得超0个赞

css3就轻松搞定哦。

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>demo</title>
    <style>
        div{width: 300px;height: 300px;background: pink;transition: all 2s ease;}
        div:hover{background: blue;}
    </style>
</head>
<body>
    <div></div>
</body>
</html>

查看完整回答
反对 回复 2016-10-11
  • 3 回答
  • 1 关注
  • 1913 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信