各位大佬真的不知道哪里錯了,物體都不能運動了
window.onload = function () {
? ? ? ? ? ? var aLi = document.getElementsByTagName('li');
? ? ? ? ? ? for(var i = 0;i<aLi.length;i++){
? ? ? ? ? ? ? ? aLi[i].timer = null;
? ? ? ? ? ? ? ? aLi[i].onmouseover = function () {
? ? ? ? ? ? ? ? ? ? startMove(this,400);
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? aLi[i].onmouseout = function (){
? ? ? ? ? ? ? ? ? ? startMove(this,200);
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ??
? ? ? ? //var timer = null;
function getStyle(obj,attr){
if(obj.currentStyle[attr]){
return obj.currentStyle[attr];//針對ie瀏覽器。
}else{
return getComputedStyle(obj,false)[attr];//針對firefox瀏覽器。
}
}
var alpha=0.3;
? ? ? ? function startMove(obj,iTarget) {
? ? ? ? ? ? clearInterval(obj.timer);
? ? ? ? ? ? obj.timer = setInterval(function () {
var icur=parseInt(getStyle(obj,'width'));
? ? ? ? ? ? ? ? var speed = (iTarget-icur)/8;
? ? ? ? ? ? ? ? speed = speed >0?Math.ceil(speed):Math.floor(speed);
? ? ? ? ? ? ? ? if(icur== iTarget){
? ? ? ? ? ? ? ? ? ? clearInterval(obj.timer);
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? else {
? ? ? ? ? ? ? ? ? ?obj.style.width=icur+speed+"px";
//obj.style.fontSize=parseInt(getStyle(obj,'font-size')+speed+'px'
? ? ? ? ? ? ? ? }
? ? ? ? ? ? },30)}
}
? ? ? ??