A simple vertical and horizontal animation effect class

Source: Internet
Author: User

Share a simple animation effect class. The idea comes from the art of Javascript DOM programming. This book is my start book of JavaScript. I have read four articles and I have often used it. I think it is also a must-have book for every JavaScript beginner. mr. think Highly recommends this book. It's really great!
The idea is actually very basic, very simple, mainly through the setTimeout () method, and the use of CSS absolute positioning to change the image position to achieve the animation effect. compiled in pure Dom mode, compatible with all browsers that support JavaScript and other APIs.
Animation Effect Core JavascriptCode:Click here to view the demo

// @ Mr. Think --- simple animation class
Function Moveelem ( Elemid , Final_x , Final_y , Interval ){
If ( ! Document . Getelementbyid ) Return False ;
If ( ! Document . Getelementbyid ( Elemid )) Return False ;
VaR ELEM = Document . Getelementbyid ( Elemid ) ;
If ( ELEM . Movement ) Cleartimeout ( ELEM . Movement ) ;
If ( ! ELEM . Style . Left ) ELEM . Style . Left = " 0px " ;
If ( ! ELEM . Style . Top ) ELEM . Style . Top = " 0px " ;
VaR Xpos = Parseint ( ELEM . Style . Left ) ;
VaR Ypos = Parseint ( ELEM . Style . Top ) ;
If ( Xpos = Final_x && Ypos = Final_y ) Return True ;
If ( Xpos < Final_x ){
VaR Divisor = Math . Ceil (( Final_x - Xpos ) / 10 );
Xpos = xpos + divisor;
}
If (xpos> final_x ){
VaR divisor = math. Ceil (xpos-final_x)
/ 10 ) ;
Xpos = Xpos - Divisor ;
}
If ( Ypos < Final_y ){
VaR Divisor = Math . Ceil (( Final_y - Ypos ) / 10 );
Ypos = ypos + divisor;
}
If (ypos> final_y ){
VaR divisor = math. Ceil (ypos-final_y)
/ 10 ) ;
Ypos = Ypos - Divisor ;
}
ELEM . Style . Left = Xpos + " Px " ;
ELEM . Style . Top = Ypos + " Px " ;
VaR Repeatelem = " Moveelem (' " + Elemid + " ', " + Final_x + " , " + Final_y + " , " + Interval + " ) " ;
ELEM . Movement = SetTimeout ( Repeatelem , Interval ) ;
}

The original post is published on mr. Think's personal blog: Http://mrthink.net/javascrip-dom-slide-simple/

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.