Advertisement
Guest User

Untitled

a guest
Mar 25th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.  
  4.  
  5. <body>
  6.  
  7.  
  8. <canvas id="bar1" class="bar" height="500" width="15" onclick="activate('bar1')"></canvas>
  9. <canvas id="bar2" class="bar" height="500" width="15" onclick="activate('bar2')"></canvas>
  10.  
  11.  
  12. <script type="text/javascript">
  13.  
  14. function activate(id){
  15. bars=document.getElementsByClassName("bar")
  16. for (var i=0; i<bars.length; i++){
  17. bars[i].style.border="solid 1px black"
  18. bars[i].removeEventListener("mousedown",function(event){click(id,event);})
  19. }
  20. bar=document.getElementById(id)
  21. bar.style.border="solid 1px red"
  22. bar.addEventListener("mousedown",function(event){click(id,event);})
  23. }
  24.  
  25. function click(id,event){
  26. console.log(event.y)
  27. bar=document.getElementById(id)
  28. move(id,event.y-bar.offsetTop)
  29.  
  30. }
  31.  
  32. function move(id,ypos){
  33. bar=document.getElementById(id)
  34. ctx=bar.getContext("2d");
  35. ctx.clearRect(0,0,bar.width,bar.height);
  36. ctx.fillRect(0,ypos,15,bar.height);
  37. }
  38.  
  39. </script>
  40.  
  41. <style type="text/css">
  42. .bar{
  43. display: inline-block;
  44. border-style: solid;
  45. border-width: 1px;
  46. border-color: black;
  47. }
  48. </style>
  49.  
  50. </body>
  51. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement