Advertisement
baseio

dskd-17-008 arcs

Apr 24th, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>arc, click to rotate</title>
  5. <style type="text/css">
  6. #svg {
  7. position: absolute;
  8. width: 300px; height:600px;
  9. top: 10px; left: 10px;
  10. border: 1px solid #ccc;
  11. }
  12. </style>
  13. </head>
  14. <body>
  15. <svg id="svg" viewBox="0 0 300 600">
  16. <path class="arc" fill="#f00" d="M150,20 M150,10v10c49.6,0,90,40.4,90,90h10C250,54.8,205.2,10,150,10L150,10"/>
  17. <path class="arc" fill="#e00" d="M150,210 M150,200v10c49.6,0,90,40.4,90,90h10C250,244.8,205.2,200,150,200L150,200"/>
  18. <path class="arc" fill="#d00" d="M150,400 M150,390v10c49.6,0,90,40.4,90,90h10C250,434.8,205.2,390,150,390L150,390"/>
  19. <path class="arc" fill="#c00" d="M150,310 M150,300v10c49.6,0,90,40.4,90,90h10C250,344.8,205.2,300,150,300L150,300"/>
  20. </svg>
  21.  
  22. <script>
  23. var arcs = document.getElementsByClassName("arc");
  24. console.log('arcs', arcs);
  25.  
  26. for(var i=0; i<arcs.length; i++){
  27. var arc = arcs[i];
  28. arc.setAttribute("rotation", 0);
  29.  
  30. arc.onclick = function(){
  31. var rot = parseInt(this.getAttribute("rotation"));
  32. //console.log('clicked', this, rot);
  33. rot += 90;
  34. //if( rot > 360 ) rot = rot - 360;
  35. this.setAttribute("rotation", rot);
  36. this.setAttribute("style", "transform: rotateZ("+ rot +"deg); transform-origin: 0% 100%; transition: transform 0.5s;");
  37. }
  38. }
  39. </script>
  40. </body>
  41. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement