Dz10Js.html 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. <link rel="stylesheet" href="style.css">
  9. </head>
  10. <style>
  11. #container1 {
  12. padding-top: 20px;
  13. padding-bottom: 20px;
  14. display: flex;
  15. justify-content: space-between;
  16. }
  17. </style>
  18. <body>
  19. <div id="container1"></div>
  20. <script>
  21. function Control(el, { value = 50,
  22. min = 0,
  23. max = 100,
  24. minAngle = -90,
  25. maxAngle = 90,
  26. wheelSpeed = 0.1,
  27. step = 1 } = {}) {
  28. const img = document.createElement('img')
  29. img.src = 'img/1@3x.png'
  30. el.append(img)
  31. const ratio = (maxAngle - minAngle) / (max - min) //цена единицы value в градусах
  32. const getAngle = () => (value - min) * ratio + minAngle //подсчитали отступ в единицах, пересчитали в градусы и прибавили к стартовому углу
  33. this.setValue = (newValue) => {
  34. if (newValue < min) {
  35. newValue = min
  36. }
  37. if (newValue > max) {
  38. newValue = max
  39. }
  40. value = newValue
  41. if (typeof this.onchange === 'function') {
  42. this.onchange(value)
  43. }
  44. img.style.transform = `rotate(${getAngle()}deg)`
  45. }
  46. this.getValue = () => value
  47. img.onmousewheel = (e) => {
  48. const { deltaY } = e
  49. //console.log(deltaY)
  50. e.preventDefault()
  51. this.setValue(value + deltaY * wheelSpeed)
  52. }
  53. img.onclick = (e) => {
  54. const { layerX } = e
  55. console.log(e, layerX)
  56. if (layerX > img.width / 2)
  57. this.setValue(value + step)
  58. else
  59. this.setValue(value - step)
  60. }
  61. this.setValue(value)
  62. }
  63. const volumeControl = new Control(container1, { value: 75, minAngle: -90 })
  64. volumeControl.onchange = (value) => {
  65. hit.volume = value / 100
  66. console.log('ON CHANGE', value)
  67. }
  68. const hit = document.createElement("audio");
  69. hit.setAttribute("controls", "");
  70. hit.src = "hit/kalush_-_stefanija_(z2.fm).mp3";
  71. hit.style.paddingLeft = "60px"
  72. document.body.append(hit);
  73. //на каждый setValue
  74. //console.log(volumeControl.getValue())
  75. //пришейте к нему тэг audio для громкости
  76. function setRGB() {
  77. let redBlock = red.getValue()
  78. let greenBlock = green.getValue()
  79. let blueBlock = blue.getValue()
  80. let rgbBlock = (block.style.background = `rgb(${redBlock},${greenBlock},${blueBlock})`)
  81. console.log('setRGB')
  82. //какой то блок, которому меняем цвет через rgba и значения крутилок
  83. }
  84. const red = new Control(container1, { min: 0, max: 255 })
  85. red.onchange = setRGB
  86. const green = new Control(container1, { min: 0, max: 255 })
  87. green.onchange = setRGB
  88. const blue = new Control(container1, { min: 0, max: 255 })
  89. blue.onchange = setRGB
  90. const block = document.createElement("div");
  91. block.style.width = "700px";
  92. block.style.height = "300px";
  93. block.style.paddingLeft = "370px"
  94. document.body.append(block);
  95. // setTimeout(() => volumeControl.setValue(80), 2000)
  96. </script>
  97. </body>
  98. </html>