為什么添加了多個動畫,后面的鏈式函數沒執行????????
<script>
function getStyle(obj,attr) {
? ?if(obj.currentStyle){
? ? ? ?return obj.currentStyle[attr];
? ?}else{
? ? ? ?return getComputedStyle(obj,false)[attr];
? ?}
}//封裝一個方法去獲得任何一個屬性值,同時方法要考慮兼容
function startMove(obj,arrt,iTarget,fn) {
? ?clearInterval(obj.timer);
? ?obj.timer=setInterval(function () {
? ? ? ?//1、判斷屬性值里是否有透明度,如有的話小數點和像素怎么處理
? ? ? ?var icur=0;
? ? ? ?if(arrt=='opacity'){
? ? ? ? ? ?icur=Math.round(parseFloat(getStyle(obj,arrt))*100);
? ? ? ?}else{
? ? ? ? ? ?icur=parseInt(getStyle(obj,arrt));
? ? ? ?}
? ? ? ?//2、算速度,速度=目標-參數m/h,并取整數
? ? ? ?var speed=(iTarget-icur)/8;
? ? ? ?speed=speed>0?Math.ceil(speed):Math.floor(speed);
? ? ? ?//檢測停止、得出透明度、得出其他值
? ? ? ?if (icur==0){
? ? ? ? ? ?clearInterval(obj.timer);
? ? ? ? ? ?if(fn){
? ? ? ? ? ? ? ?fn();
? ? ? ? ? ?}
? ? ? ?}else{
? ? ? ? ? ?if (arrt=='opacity'){
? ? ? ? ? ? ? ?obj.style.filter='alpha:(opacity:'+icur+speed+')';
? ? ? ? ? ? ? ?obj.style.opacity=(icur+speed)/100;
? ? ? ? ? ?}else {
? ? ? ? ? ? ? ?obj.style[arrt]=icur+speed+'px';
? ? ? ? ? ?}
? ? ? ?}
? ?},30)
}
/////// ? ?以上是一個框架 ? ///////
window.onload=function () {
? ?var Li=document.getElementById('li1');
? ?Li.onmouseover=function () {
? ? ? ?startMove(Li,'height',200,function(){
? ? ? ? ? ?startMove(Li,'width',400,function(){
? ? ? ? ? ? ? ?startMove(Li,'opacity',100);
? ? ? ? ? ?})
? ? ? ?})
? ?}
}
2017-10-18
attr 與 arrt??
2017-09-21
? ?if (icur==iTarget){ ? //判斷條件是到達目標 ?而不是==0
? ? ? ? ? ?clearInterval(obj.timer);
? ? ? ? ? ?if(fn){
? ? ? ? ? ? ? ?fn();
? ? ? ? ? ?}
2017-09-21
你調用封裝的框架沒看看!