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/