求大佬指教,應該是調(diào)用的框架有問題,代碼寫的是更改width,QQ和Chrome上卻改變的是透明度,請大佬指教
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>JS鏈式運動</title>
<style type="text/css">
body {
margin: 0;
padding: 0;
}
ul,
? ? ? ?li {
list-style: none;
}
li {
width: 200px;
height: 100px;
background-color: brown;
margin-bottom: 20px;
border: 4px solid#000;
filter: alpha(opacity, 30);
opacity: 0.3;
}
</style>
<script src="鏈式動畫框架.js"> </script>
<script>
window.onload = function () {
var Li = document.getElementById('li1');
Li.onmouseover = function () {
startMove(Li,'width',400);
}
}
</script>
</head>
<body>
<ul>
<li id="li1"></li>
</ul>
</body>
</html>
//////////////////////////////////////////////////////////調(diào)用框架
function getStyle(obj, attr) {
? ?if (obj.currentStyle) {
? ? ? ?return obj.currentStyle[attr];
} else {
? ? ? ?return getComputedStyle(obj, false)[attr];
}
}
function startMove(obj, attr, iTarget) {
clearInterval(obj.timer);
? ?obj.timer = setInterval(function () {
? ? ? ?//1. 去當前的值
? ? ? ?var icur = 0;
? ? ? ?if (attr = 'opacity') {
? ? ? ? ? ?icur = Math.round((getStyle(obj, attr)) * 100);
} else {
? ? ? ? ? ?icur = parseInt(getStyle(obj, attr));
}
? ? ? ?//2. 算速度
? ? ? ?var speed = (iTarget - icur) / 8;
? ? ? ?speed = speed > 0 ? Math.ceil(speed) : Math.floor(speed);
? ? ? ?//3. 檢測停止
? ? ? ?if (icur == iTarget) {
clearInterval(obj.timer);
} else {
? ? ? ? ? ?if (attr == 'opacity') {
? ? ? ? ? ? ? ?obj.style.filter = 'alpha(opacity:' + (icur + speed) + ')'; //IE瀏覽器整數(shù)幾十
? ? ? ? ? ? ? ?obj.style.opacity = (icur + speed) / 100; //火狐or chrome,小數(shù)零點幾
} else {
? ? ? ? ? ? ? ?obj.style[attr] = icur + speed + 'px';
}
}
}, 30)
}
2018-09-13
icur = Math.round((getStyle(obj, attr)) * 100);
這句應該改成
icur=Math.round(parseFloat(getStyle(obj,attr))*100);