Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. ball.ondragstart = function() {
  2. return false;
  3. };
  4.  
  5. <img src="./samyak/images/0.jpeg" style="cursor: pointer; position: absolute; z-index: 1000; left: 777px; top: 39px; transition: auto 0s ease 0s;" width="40" height="40" id="ball">
  6. <script>
  7. ball = document.getElementById("ball");
  8. ball.style.transform="rotate(30deg)"
  9. ball.ondragstart = function() {
  10. return false;
  11. };
  12. ball.onmousedown = function(event) { // (1) start the process
  13.  
  14. // (2) prepare to moving: make absolute and on top by z-index
  15. ball.style.position = 'absolute';
  16. ball.style.zIndex = 1000;
  17. // move it out of any current parents directly into body
  18. // to make it positioned relative to the body
  19. document.body.append(ball);
  20. // ...and put that absolutely positioned ball under the cursor
  21.  
  22. moveAt(event.pageX, event.pageY);
  23.  
  24. // centers the ball at (pageX, pageY) coordinates
  25. function moveAt(pageX, pageY) {
  26. ball.style.left = pageX - ball.offsetWidth / 2 + 'px';
  27. ball.style.top = pageY - ball.offsetHeight / 2 + 'px';
  28. }
  29.  
  30. function onMouseMove(event) {
  31. moveAt(event.pageX, event.pageY);
  32. }
  33.  
  34. // (3) move the ball on mousemove
  35. document.addEventListener('mousemove', onMouseMove);
  36.  
  37. // (4) drop the ball, remove unneeded handlers
  38. ball.onmouseup = function() {
  39. document.removeEventListener('mousemove', onMouseMove);
  40. ball.onmouseup = null;
  41. };
  42.  
  43. }
  44. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement