能幫我看看哪里出錯(cuò)了么?
window.onload = function () {
/*var ali = document.getElementsByTagName('li'); // 獲取LI
? ? ? ? ? ?for (var i = 0; i < ali.length; i++) {
? ? ? ? ? ? ? ?ali[i].timer = null; //使用數(shù)組寫法定義獨(dú)立的定時(shí)器,避免公用定時(shí)器的爭(zhēng)搶。
? ? ? ? ? ? ? ?ali[i].onmouseover = function () {
? ? ? ? ? ? ? ? ? ?stratMove(this, 400);
? ? ? ? ? ? ? ?}
? ? ? ? ? ? ? ?ali[i].onmouseout = function () {
? ? ? ? ? ? ? ? ? ?stratMove(this, 200);
? ? ? ? ? ? ? ?}
? ? ? ? ? ?}
? ? ? ?}*/
var Li1 = document.getElementById('li1');
//var Li2 = document.getElementById('li2');
Li1.onmouseover = function () {
startMove(this, 'opacity',100);
}
Li1.onmouseout = function () {
stratMove(this, 'opacity', 30);
}
}
//var timer = null; //定義一個(gè)定時(shí)器,取消公用定時(shí)器
var alpha = 30;
function startMove(obj, attr, iTarget) {
clearInterval(obj.timer);
obj.timer = setInterval(function () {
var icur = 0;
if (attr == 'opacity') {
//Math.round()將一個(gè)數(shù)四舍五入為一個(gè)最接近的整數(shù)
icur = Math.round(parseFloat(getStyle(obj, attr)) * 100);
} else {
icur = parseInt(getStyle(obj, attr));
}
var speed = (iTarget - icur) / 8;
speed = speed > 0 ? Math.ceil(speed) : Math.floor(speed);
if (icur == iTarget) {
clearInterval(obj.timer);
} else {
if (attr == 'opacity') {
obj.style.filter = 'alpha(opacity('+(icur+speed)+')';
obj.style.opacity = (icur + speed) / 100;
} else {
obj.style[attr] = icur + speed;
}
}
}, 30);
}
function getStyle(obj, attr) {
if (obj.currentStyle) {
return obj.currentStyle[attr];
} else {
return getComputedStyle(obj, false)[attr];
}
} //封裝獲取樣式元素
2018-01-17
Li1.onmouseout = function () {
stratMove(this, 'opacity', 30);
}
start拼寫錯(cuò)誤,其他沒(méi)看