js原生簡單實現animate操作Css3屬性

來源:互聯網
上載者:User

標籤:

最近寫HTML5+CSS3頁面發現Jquery沒法操作transform:旋轉等一些效果所以自己簡單寫了個

<script type="text/javascript">    window.onload = function(){var func = function(){            var isdie = false;            this.animate = function(obj,name,time){                var arr1 = [‘rotate‘];                if(!isdie){                    var num = 0.0000000001;                    isdie = true;                    var isCss3 = false;                    var isdie = true;                    var isZ = true;                                        for(var o in name){                        if(o.indexOf(‘:‘) > 0){                            isCss3 = true;                            O = o.split(":");                        }                        if(isCss3){                            var num = parseFloat(obj.style[""+O[0]+""].match(/([0-9])+/, ""));                        }else{                            var num = parseFloat(func.getStyle(obj,""+o+"").match(/([0-9])+/, ""));                        }                        // alert(num)                        if(!num){                            var num = 0;                        }                        var Interval = setInterval(function(){                            if(parseFloat(name[o]) > num){                                num+=0.9876543210;                            }else if(parseFloat(name[o]) < num){                                num-=0.9876543210;                                isZ = false;                            }else{                                num = 0;                            }                            // alert(num);                            if(isCss3){                                var val = O[1]+"("+num+name[o].replace(/[(\d+)||(\d+.\d+)]+/,"")+")";                                obj.style[""+O[0]+""]=val;                            }else{                                var val = ""+num+name[o].replace(/[(\d+)||(\d+.\d+)]+/,"")+"";                                obj.style[""+o+""]=val;                            }                            // alert(val);                            if(num > name[o].replace(/([a-z])+/, "") && isZ || num < name[o].replace(/([a-z])+/, "") && !isZ){                                isdie = false;                                clearInterval(Interval);                                if(isCss3){                                    obj.style[""+O[0]+""]=O[1]+"("+name[o].replace(/([a-z])+/, "")+name[o].replace(/[(\d+)||(\d+.\d+)]+/,"")+")";                                }else{                                    obj.style[""+o+""]=""+name[o].replace(/([a-z])+/, "")+name[o].replace(/[(\d+)||(\d+.\d+)]+/,"")+"";                                }                            }                        },time);                    }                }                return this;            }            this.inarray = function(b,a){                for (var i = 0; i <= a.length - 1; i++) {                    if(a[i] == b){                        return true;                    }                    return false;                };            }            this.getStyle = function (el, style){               if(!+"\v1"){                 style = style.replace(/\-(\w)/g, function(all, letter){                   return letter.toUpperCase();                 });                 return el.currentStyle[style];               }else{                 return document.defaultView.getComputedStyle(el, null).getPropertyValue(style)               }                }            }        var func = new func();        func.animate(line[3].getElementsByClassName(‘sanjiao‘)[0],{"height":"200px"},1);
// func.animate(要操作的對象,{要操作的屬性},變換的速度);
//使用方法和jquery 如果要操作 width height等一些元素直接{"height":"200px"}就可以了如果是css3比如transform:rotate(100deg)就應該這麼寫{"transform:rotate":"100deg"}
//暫時不支援操作多個屬性進行動畫效果(待添加!)
//暫時不支援負數(待添加!)
//寫的不好還請多多見諒! }
</script>

 

js原生簡單實現animate操作Css3屬性

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.