Javascript Function

Javascript Tutorials, Ajax , Validation, Calculator, DOM

« DOM Event Processing Puting it All Together »

Selecting an End Position

In the last tutorial we saw how we could easily move our object by a set distance (100 pixels in the example). To be able to move the object to a set position on the screen regardless of how far away that is just requires that we calculate the end position in a different way. Instead of the start position (xxx) less the distance to move was can instead specify the end position relative to the width of the screen. For example:

endPos = (pageWidth()-objWidth('myobj'))/2;

This sets the end position to be the centre of the window (at least horizontally). We need to place the left hand edge of the object half the width of the object to the left of a position half way across the screen so that the object will be exactly centred.

All of the other code for the animation would remain unchanged since we are only redefining the end position.

If we wanted to position the objects end position relative to the left hand edge of the screen we would use a fixed distance from posLeft() as our end position.

Post comment:

◎welcome to give out your point。

Calendar

Comments

Previous

Powered By http://www.javascriptfunction.com Godaddy Promo Code

Copyright http://www.javascriptfunction.com/. All Rights Reserved.