javascript - how to Change The Position of a sprite? -
<?php $left=307; $top=282; ?> <html> <head> </head> <body> <script> function move() { var x=20; var left=<?php echo $left ?>; var left=left + x; document.getelementbyid("demo").style.left= left + "px"; var x=x+5; } </script> <img src="images/map2.png" style="position:absolute"> <img id="demo" src="images/avatars/0down.png" style="position:absolute; left:<?php echo $left ?>; top:<?php echo $top ?>"> <img src="images/arrow_right.png" style="position:absolute" onclick="move()"> </body> </html>
this entire code(incomplete know)! trying move sprite 1 place another! new in coding! , bit impatient .. can judge coding guess :p.. anyways, in code can't understand 1 thing!.. first time when clicking arrow! first time move sprite!... instantly when clicking 2nd time! not having effect! :|.. appreciated :))
you defining x
, left
inside function, each time call function resetting default values. on 2nd nth times out moving same place. try moving before function.
<script> x=20; left=<?php echo $left ?>; function move() { left+=x; document.getelementbyid("demo").style.left= left + "px"; x+=5; } </script>
Comments
Post a Comment