beatInfiniteLoop.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <template>
  2. <div class="beat-wrapper">
  3. <input v-model="divisioni" type="number" min="1" oninput="validity.valid||(value='');">
  4. <!--- trovare modo per prevenire scrittura di input-->
  5. <div class="division-wrapper">
  6. <div class="beat" v-for="j in nDivisioni" :key='j' >
  7. <!--<div>{{randomColori()}}</div>-->
  8. <div class="suddivisione" :style="{'background-color': colore }" style="max-width:1em" :id="nome">{{titolo(j)}}</div>
  9. </div>
  10. </div>
  11. </div>
  12. </template>
  13. <script>
  14. export default {
  15. name: 'beat',
  16. data() {
  17. return {
  18. nome:'',
  19. colore: 'red',
  20. divisioni: 1,
  21. timing: 0
  22. }
  23. },
  24. computed: {
  25. nDivisioni() {
  26. var n = parseInt(this.divisioni);
  27. return isNaN(n) ? 0 : n;
  28. }
  29. },
  30. methods: {
  31. randomColori: function (){
  32. var letters = '0123456789ABCDEF';
  33. var color = '#';
  34. for (var i = 0; i < 6; i++) {
  35. color += letters[Math.floor(Math.random() * 16)];
  36. }
  37. // console.log(color);
  38. this.colore = color;
  39. },
  40. getTime: function(){
  41. // https://stackoverflow.com/questions/288699/get-the-position-of-a-div-span-tag#288731
  42. var el = document.getElementById(this.nome);
  43. for (var lx=0, ly=0;
  44. el != null;
  45. lx += el.offsetLeft, ly += el.offsetTop, el = el.offsetParent);
  46. console.log("x :"+ lx+", y :"+ly);
  47. },
  48. titolo(progressivo){
  49. this.nome = "nomeBeat" + progressivo;
  50. }
  51. }
  52. }
  53. </script>
  54. <style>
  55. .beat{
  56. flex: 1 1 auto;
  57. width: 100%;
  58. height: 100%;
  59. }
  60. .active{
  61. background-color:black;
  62. }
  63. input {
  64. background:transparent;
  65. width:2em;
  66. }
  67. .division-wrapper {
  68. flex:1 1 auto;
  69. display: flex;
  70. }
  71. .beat {
  72. height:1em;
  73. display:flex;
  74. flex:1 1 auto;
  75. }
  76. .suddivisione{
  77. flex:1 1 auto;
  78. border:none;
  79. }
  80. input[type=number]::-webkit-inner-spin-button,
  81. input[type=number]::-webkit-outer-spin-button {
  82. -webkit-appearance: none;
  83. -moz-appearance: none;
  84. appearance: none;
  85. margin: 0;
  86. }
  87. input[type=number] {
  88. -moz-appearance:textfield;
  89. padding-left:0.2em;
  90. color:lightgray;
  91. border:none;
  92. }
  93. </style>