Browse Source

修复了在移动端一次点击响两下的bug

LiuLiu 4 years ago
parent
commit
0bb96bbb25
1 changed files with 9 additions and 5 deletions
  1. 9 5
      index.html

+ 9 - 5
index.html

@@ -52,8 +52,9 @@
             outline: 0px;
             appearance: none;
         }
+
         .huaji:hover,
-        .huaji.down{
+        .huaji.down {
             border-bottom-color: rgb(232, 167, 84);
             cursor: pointer;
         }
@@ -195,13 +196,15 @@
                         press = false
                     }, 500);
                 }
-                button.down_press = button.onmousedown = down_press
-                button.down_move = button.onmouseenter = down_move
+                button.touchMode = button.press = false
+                button.down_press = button.onmousedown = function (e) {if (this.touchMode) this.touchMode = false; else down_press(e)}
+                button.down_move = button.onmouseenter = function (e) {if (this.touchMode) this.touchMode = false; else down_move(e)}
                 button.up_press = button.onmouseup = up_press
                 button.up_move = button.onmouseleave = up_move
                 button.ontouchstart = function (event) {
                     // console.log("touchStart", event)
                     // event.preventDefault();
+                    this.touchMode = true
                     down_press(event);
                     this.lastPostionWasHere = true
                     this.press = true;
@@ -235,6 +238,7 @@
                                 const button = buttons[index];
                                 if (touch.pageX > button.offsetLeft && touch.pageX < button.offsetLeft + button.offsetWidth && touch.pageY > button.offsetTop && touch.pageY < button.offsetTop + button.offsetHeight) {
                                     if (!button.lastPostionWasHere) {
+                                        button.touchMode = true
                                         button.down_move({target: button})
                                         // console.log("MoveIn")
                                         // console.log(button)
@@ -276,8 +280,8 @@
                         var pianoKey = data.note - 21;
                         // console.log('note', MIDI.noteToKey[data.note])
                         if (data.message == 144) {
-                            time.value = data.now*1000
-                            time.max = data.end*1000
+                            time.value = data.now * 1000
+                            time.max = data.end * 1000
                             buttons[pianoKey] && buttons[pianoKey].classList.add("down")
                         } else {
                             buttons[pianoKey] && buttons[pianoKey].classList.remove("down")