Guest User

Untitled

a guest
Apr 26th, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. <script src="//code.jquery.com/jquery-1.10.2.js"></script>
  2. <script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
  3.  
  4. var $newPosX = 100,
  5. $newPosY = 100;
  6.  
  7. //create image node
  8. var x = document.createElement("IMG");
  9. x.src = "http://upload.wikimedia.org/wikipedia/commons/a/a4/Sol_de_Mayo_Bandera_Argentina.png";
  10. x.width = 100;
  11. x.height = 100;
  12. x.id = "sun";
  13. x.hspace = 100;
  14. x.vspace = 100;
  15. document.body.appendChild(x);
  16.  
  17. //coords
  18. var text = document.createTextNode($newPosX + " " + $newPosY);
  19. document.body.appendChild(text);
  20.  
  21. //make sun draggable and update coords
  22. $("#sun").draggable({
  23. drag: function (event, ui) {
  24. $newPosX = $(this).offset().left;
  25. $newPosY = $(this).offset().top;
  26. }
  27. });
  28.  
  29. //0 millisecond update for displayed coords
  30. setInterval(check, 0);
  31.  
  32. function check() {
  33. //tries to constrain movement, doesn't work well
  34. /*
  35. if ($newPosX > 300) {
  36. $("#sun").offset({
  37. left: 200
  38. });
  39. }
  40. */
  41. text.nodeValue = ($newPosX + " " + $newPosY);
  42. }
Add Comment
Please, Sign In to add comment