Guest User

Untitled

a guest
Aug 29th, 2019
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.75 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title></title>
  5. <link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  6. <style type="text/css">
  7. .draggable {
  8. width: 50px;
  9. height: 50px;
  10. padding: 0.5em;
  11. float: left;
  12. margin: 0 10px 10px 0;
  13. cursor:move;
  14. margin-bottom:20px;
  15. }
  16. h3 {
  17. clear: left;
  18. }
  19. </style>
  20. <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  21. <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
  22. </head>
  23. <body>
  24. <div>
  25. <svg id="svg1 containment-wrapper" style="position: absolute;left:0px;top:0px;width: 100%;height:100%">
  26. <circle
  27. class="ui-widget-content draggable"
  28. id="B1"
  29. cx="100"
  30. cy="200"
  31. style="vector-effect:non-scaling-stroke;fill:#ffff00;fill-opacity:1;stroke:#000000;stroke-width:1px"
  32. r="20" />
  33. <circle
  34. class="ui-widget-content draggable"
  35. id="B2"
  36. cx="200"
  37. cy="200"
  38. style="vector-effect:non-scaling-stroke;fill:#ffff00;fill-opacity:1;stroke:#000000;stroke-width:1px"
  39. r="20" />
  40. <circle
  41. class="ui-widget-content draggable"
  42. id="B3"
  43. cx="300"
  44. cy="200"
  45. style="vector-effect:non-scaling-stroke;fill:#ffff00;fill-opacity:1;stroke:#000000;stroke-width:1px"
  46. r="20" />
  47. <circle
  48. class="ui-widget-content draggable"
  49. id="B4"
  50. cx="400"
  51. cy="200"
  52. style="vector-effect:non-scaling-stroke;fill:#ffff00;fill-opacity:1;stroke:#000000;stroke-width:1px"
  53. r="20" />
  54. </svg>
  55. </div>
  56.  
  57. <script type="text/javascript">
  58. $(document).on("ready", function(){
  59. var sPositions = localStorage.positions || "{}",
  60. positions = JSON.parse(sPositions);
  61. $.each(positions, function (id, pos) {
  62. console.log("#" + id + ": " + pos);
  63. $("#" + id).attr(pos);
  64. })
  65. $(".draggable").draggable({
  66. containment: "#containment-wrapper",
  67. stop: function (event, ui) {
  68. positions[this.id] = "{'cx': '" + ui.position.left + "', 'cy': '" + ui.position.top + "'}"
  69. localStorage.positions = JSON.stringify(positions)
  70. }
  71. }).bind('drag', function(event, ui){
  72. event.target.setAttribute('cx', ui.position.left);
  73. event.target.setAttribute('cy', ui.position.top);
  74. });
  75. })
  76. </script>
  77. </body>
  78. </html>
Advertisement
Add Comment
Please, Sign In to add comment