課程
/前端開發(fā)
/JavaScript
/JS動畫效果
麻煩能不能把代碼放出來
2016-05-24
源自:JS動畫效果 2-2
正在回答
move.js
function getStyle(obj,attr){
if(obj.currentStyle){
return obj.currentStyle[attr];//currentStyle針對IE瀏覽器
}else{
return getComputedStyle(obj,false)[attr];//getComputedStyle針對火狐瀏覽器
}
function startMove(obj,json,fn){
var flag = true;
clearInterval(obj.timer);
obj.timer=setInterval(function(){
for(var attr in json)
{
var icur=0;
if(attr=='opacity'){
icur=Math.round(parseFloat(getStyle(obj,attr))*100);
icur=parseInt(getStyle(obj,attr));
var speed = (json[attr]-icur)/8;
speed = speed>0?Math.ceil(speed):Math.floor(speed);
if(icur != json[attr]){
flag=false;
obj.style.filter='alpha(opacity:'+(icur+speed)+')';
obj.style.opacity=(icur+speed)/100;
}else{obj.style[attr] = icur+speed+'px';}
if(flag){
if(fn){
fn();
},30)
舉報(bào)
通過本課程JS動畫的學(xué)習(xí),從簡單動畫開始,逐步深入各種動畫框架封裝
4 回答能吧代碼發(fā)上來么;沒代碼看
1 回答任意值運(yùn)動怎么俺寫出來的代碼不能兼容IE ?
2 回答每次她都不把提前寫出來的代碼放以下,直接往下敲要做的效果
3 回答代碼寫入for循環(huán)就沒有效果,把每一項(xiàng)單獨(dú)寫出來能出現(xiàn)效果,這是為什么?
1 回答能不能別總說OK啊 老師
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網(wǎng)安備11010802030151號
購課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號
2016-05-24
move.js
function getStyle(obj,attr){
if(obj.currentStyle){
return obj.currentStyle[attr];//currentStyle針對IE瀏覽器
}else{
return getComputedStyle(obj,false)[attr];//getComputedStyle針對火狐瀏覽器
}
}
function startMove(obj,json,fn){
var flag = true;
clearInterval(obj.timer);
obj.timer=setInterval(function(){
for(var attr in json)
{
var icur=0;
if(attr=='opacity'){
icur=Math.round(parseFloat(getStyle(obj,attr))*100);
}else{
icur=parseInt(getStyle(obj,attr));
}
var speed = (json[attr]-icur)/8;
speed = speed>0?Math.ceil(speed):Math.floor(speed);
if(icur != json[attr]){
flag=false;
}
if(attr=='opacity'){
obj.style.filter='alpha(opacity:'+(icur+speed)+')';
obj.style.opacity=(icur+speed)/100;
}else{obj.style[attr] = icur+speed+'px';}
}
if(flag){
clearInterval(obj.timer);
if(fn){
fn();
}
}
},30)
}