Trying To Write A Script To Push A Box Using Mouse Pointer In Javascript
I'm in the beginning of learning Javascript, and trying to write a script that allows the user to push a box left and right using mouse pointer. I managed to work it out when the
Solution 1:
Possible idea for you. Sounds like some carousels I've coded up in AS3.
- When mouse over the div container for the box you start checking mouse position on a timer (fairly fast).
- using mouse X, div width, box width you can calculate if the mouse is on the left or the right of the box. You probably want ranged hit area on both sides of the box so that it moves when mouse hits that to new position. (I assume your box is position relative css inside its container which will allow css:left and css:right to be animated via document.getElementById("xxx").style
- Careful when box gets to left and right side limits as you still want a hit area.
I would suggest creating a few text boxes for number outputs so you can see how numbers change when your timer function is checking mouse positions etc and then you should be able to make the calculations.
Hope this helps.
Post a Comment for "Trying To Write A Script To Push A Box Using Mouse Pointer In Javascript"