谁能告诉我为什么我的这个代码会透明度先降低到0.08再开始增加
javascript吧
全部回复
仅看楼主
level 2
<!DOCTYPE html>
<html>
<head>
<style type="text/css">div {
width: 200px;
height: 200px;
background: red;
opacity: 0.3;
}</style>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<div id="box"></div>
</body>
<script type="text/javascript">
var s = null;
window.onload = function() {
var box = document.getElementById("box");
box.onmouseover = function() {
startMove(100)
}
box.onmouseout = function() {
startMove(30)
}
}
function startMove(tou) {
clearInterval(s);
var speed = 0;
s = setInterval(function() {
var touming = box.style.opacity*100;
if(touming < tou) {
speed = 10;
}else{
speed = -10;
}
if(touming == tou) {
clearInterval(s);
} else {
box.style.opacity = (box.style.opacity*1000+speed) / 1000;
}
}, 50)
}
</script>
</html>
以上这些是代码谢谢万能的吧友们。
2020年05月26日 07点05分 1
level 2
小白求解
2020年05月26日 07点05分 2
level 2

2020年05月26日 07点05分 3
level 12
把透明度写div里 不然得用 getComputedStyle() 来获取 [乖]<div id="box" style="opacity:0.3;"></div>
2020年05月27日 01点05分 5
level 2
我能说老师讲完我是一脸懵逼嘛,我按着他教的写全是报错,谢啦老哥。
2020年05月28日 07点05分 6
你应该是抄错了吧。。。 [小乖]
2020年05月28日 12点05分
level 1
。。。。。上课听,下课按着视频敲啊
2020年05月28日 09点05分 7
level 13
2020年05月28日 16点05分 8
level 2
贴吧真是个神奇的东西,
2020年05月30日 02点05分 9
level 2
感谢
2020年05月30日 02点05分 10
1