課程
/前端開發
/JavaScript
/網頁廣告特效
沒有源碼參考哦,老師,麻煩提供一下源碼把。謝謝
2015-06-01
源自:網頁廣告特效 3-3
正在回答
startMove,去聽下DOM基本事件那屆! function?startMove(obj,json,?fun) { clearInterval(obj.timer); obj.timer=setInterval ( function() { for(var?attr?in?json) //得到屬性 { //取當前的值 var?cur=0; if(attr?==?'opacity') //如果屬性為透明度 { cur?=?Math.round(parseFloat(getStyle(obj,?attr))*100); } else { var?cur=parseInt(getStyle(obj,?attr)); } //算速度 //var?speed=(target-obj.offsetWidth)/8; var?speed=(json[attr]-cur)/8; speed=?(speed>0)???Math.ceil(speed)?:?Math.floor(speed); //檢測停止 //if(obj.offsetWidth?==?target) if(cur?==?json[attr]) { clearInterval(obj.timer); if(fun) { fun(); } } else { if(attr?==?'opacity') { obj.style.filter?=?'alpha(opacity:'+(cur+speed)+')'; obj.style.opacity=(cur+speed)/100; } else { //divs.style.width=divs.offsetWidth-1+'px'; //offsetWidth=208px(整個div的寬度margin?padding?border) width=208-1px 207+8-1...... //divs.style.width=parseInt(divs.style.width)-1+'px'; //width寫在行 obj.style[attr]=cur+speed+'px'; } } } },30 ); } function?getStyle(obj,?attr) //獲取CSS樣式 { if(obj.currentStyle) //IE { return?obj.currentStyle[attr]; } else { return?getComputedStyle(obj,?false)[attr]; } }//?JavaScript?Document
舉報
原來這么EASY,從淺到深,逐步優化代碼,讓你深入理解
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2016-04-19