Primitive JS Package element motion function __javascript

Source: Internet
Author: User

First look at the demo effect
code, function argument obj is the element that you want to change at the moment, changedata for the kind of change you want, for example, func the function you want to process after the element action ends

For example, to the above demo, Note: opacity to be multiplied by 100 for the following code

var div = document.getelementsbyclassname (' demo ') [0];
    Startmove (Div, {width:200,  height:200, left:100, top:100, opacity:50}, function () {});
/* * Motion Function Model * * functions startmove (obj, Changedata, func) {clearinterval (Obj.timer);
    var icurvalue = 0;
    var ispeed = 0;

    var bstop; Obj.timer = Window.setinterval (function () {bstop = true;//to determine whether all current actions are fully executed for (var name in Changedata)
            {Console.log (name, Changedata[name]);
            if (name = = = = = ' opacity ') {//When processing transparency to pay attention to increase the multiple, otherwise easy to cause the bug Icurvalue = parsefloat (GetStyle (obj, name)) * 100;
            }else {icurvalue = parseint (GetStyle (obj, name)); } Ispeed = (Changedata[name]-icurvalue)/7;//buffering Motion effect if (Ispeed > 0) {ispeed
            = Math.ceil (ispeed);
            }else{ispeed = Math.floor (ispeed);         
            } if (name = = = ' opacity ') {obj.style.opacity = (Icurvalue + ispeed)/100;
            }else{Obj.style[name] = icurvalue + ispeed + ' px '; } if (Icurvalue !== Changedata[name]) {bstop = false;
            } if (bstop) {//entire action completed clearinterval (Obj.timer);
        Func ()//////////////////////
}, 30);
 }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.