js 動畫3 完美架構

來源:互聯網
上載者:User

標籤:seo   nal   one   put   title   height   cti   XML   als   

js 架構:
function getStyle(obj,attr){if(obj.currentStyle){return obj.currentStyle[attr];}else{return getComputedStyle(obj,false)[attr];}}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)}

鏈式動畫(前一個動作完畢。後一個動作繼續):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>鏈式架構</title><style>body,ul,li{margin:0;padding:0;}ul,li{ list-style:none;}ul li{width:200px;height:100px;margin-bottom:10px;background:yellow;border: 4px solid #000;filter:alpha(opacity:30);opacity: 0.3;}</style><script src="move.js"></script><script>window.onload = function(){var li = document.getElementById(‘li1‘);li.onmouseover = function(){startMove(li,‘width‘,400,function(){startMove(li,‘height‘,200,function(){startMove(li,‘opacity‘,100);});});}li.onmouseout = function(){startMove(li,‘opacity‘,30,function(){startMove(li,‘height‘,100,function(){startMove(li,‘width‘,200);});});}}</script></head><body><ul><li id="li1"></li></ul></body></html>


同一時候動畫(多個動作同一時候完畢):
 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>同一時候動畫</title><style>body,ul,li{margin:0;padding:0;}ul,li{ list-style:none;}ul li{width:200px;height:100px;margin-bottom:10px;background:yellow;border: 4px solid #000;filter:alpha(opacity:30);opacity: 0.3;}</style><script src="move.js"></script><script>window.onload = function(){var oli = document.getElementById(‘li1‘);oli.onmouseover = function(){startMove(oli,{width:400,height:200,opacity:100});}oli.onmouseout = function(){startMove(oli,{width:200,height:100,opacity:30});}}</script></head><body><ul><li id="li1"></li></ul></body></html>



js 動畫3 完美架構

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.