index.html 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8" />
  5. <meta name="viewport" content="width=device-width" />
  6. <title>Другой тайтл ПРИВЕТ 17й</title>
  7. <style>
  8. </style>
  9. </head>
  10. <body>
  11. <div id='container1'>
  12. <audio controls id="myaudio">
  13. <source src="DC.mp3">
  14. </audio>
  15. </div>
  16. <div id='container2'>
  17. <div id="color" style="border-radius: 100px; width: 150px; height: 150px;"></div>
  18. </div>
  19. <script>
  20. function Control(el, { value = 0, min = 0, max = 100, minAngle = 0, maxAngle = 360, wheelSpeed = 0.1, step = 10 } = {}) {
  21. const img = document.createElement('img')
  22. img.src = '1@3x.png'
  23. img.setAttribute("style", "width: 150px; height: 150px; margin: 10px 10px 10px 0px;")
  24. el.append(img)
  25. const ratio = (maxAngle - minAngle) / (max - min)
  26. const getAngle = () => minAngle + (this.value - min) * ratio
  27. const setValue = newValue => {
  28. if (newValue > max)
  29. newValue = max
  30. if (newValue < min)
  31. newValue = min
  32. this.value = newValue
  33. img.style.transform = `rotate(${getAngle()}deg)`
  34. console.log(value)
  35. }
  36. setValue(value)
  37. this.setValue = setValue
  38. img.onmousewheel = e => {
  39. const { deltaY } = e
  40. e.preventDefault()
  41. setValue(this.value + deltaY * wheelSpeed)
  42. this.onchange()
  43. }
  44. img.onclick = e => {
  45. const { layerX } = e
  46. if (layerX < 100) {
  47. setValue(this.value - step)
  48. } else {
  49. setValue(this.value + step)
  50. }
  51. this.onchange()
  52. }
  53. }
  54. /////
  55. const volumeControl = new Control(container1, { value: 0, min: 0, max: 100, minAngle: -90, maxAngle: +90 })
  56. let text = document.createElement('span')
  57. volumeControl.onchange = () => {
  58. let audio = document.getElementById("myaudio")
  59. audio.volume = volumeControl.value * 0.01
  60. text.innerText = `volume = ${volumeControl.value}`
  61. container1.append(text)
  62. }
  63. const redControl = new Control(container2, { value: 0, min: 0, max: 255, minAngle: -90, maxAngle: +90 })
  64. const greenControl = new Control(container2, { value: 0, min: 0, max: 255, minAngle: -90, maxAngle: +90 })
  65. const blueControl = new Control(container2, { value: 0, min: 0, max: 255, minAngle: -90, maxAngle: +90 })
  66. let color = document.getElementById('color')
  67. redControl.onchange = () => { color.style.backgroundColor = `rgb(${redControl.value}, ${greenControl.value}, ${blueControl.value})` }
  68. greenControl.onchange = () => { color.style.backgroundColor = `rgb(${redControl.value}, ${greenControl.value}, ${blueControl.value})` }
  69. blueControl.onchange = () => { color.style.backgroundColor = `rgb(${redControl.value}, ${greenControl.value}, ${blueControl.value})` }
  70. </script>
  71. </body>
  72. </html>