var paw = document.getElementById("paw"); var keyboard = document.querySelector(".keyboard"); let sampler = new Tone.Sampler({ urls: { // F3: "cow_F3.mp3", // F5: "cat_F5.mp3", F4: "mariopaintmeow.mp3" }, baseUrl: "https://amplify-education.github.io/hackathon-Auto-Meow-Tone/samples/" }).toDestination(); function showCoords(event) { var x = event.clientX; var y = event.clientY; var target = event.target; var coor = "X coords: " + x + ", Y coords: " + y; paw.style.left = x + "px"; var botton = window.innerHeight - keyboard.parentElement.offsetTop - keyboard.offsetHeight; if (target.classList.contains("black")) { paw.style.bottom = botton - 20 + "px"; } else if (target.classList.contains("white")) { paw.style.bottom = botton - 70 + "px"; } } function clearCoor() { paw.style.bottom = -120 + "px"; } document.addEventListener("mousedown", function (e) { var target = e.target; if (target.hasAttribute("data-key")) { paw.classList.remove("up"); paw.classList.add("down"); console.log(target.offsetWidth); makeNotes( target.getAttribute("data-key"), target.offsetLeft, target.offsetWidth ); sampler.triggerAttackRelease(target.getAttribute("data-key"), 1); } }); document.addEventListener("mouseup", function (e) { paw.classList.remove("down"); paw.classList.add("up"); }); function makeNotes(key, x, w) { var left; var height; var width; if (w > 35) { left = x; width = w - 6; height = width; } else { left = x - w / 2; width = w; height = width; } var newnote = document.createElement("span"); newnote.classList.add("user"); newnote.setAttribute( "style", "margin-left:" + left + "px; width:" + width + "px;" ); moveNotes(newnote); newnote.innerHTML = ""; document.getElementById("notes").appendChild(newnote); } function moveNotes(elem) { var pos = 0; var max = 600; var id = setInterval(frame, 10); console.log("max" + keyboard.offsetTop); function frame() { if (pos == max) { clearInterval(id); elem.remove(); } else { pos++; elem.style.bottom = pos + "px"; } } }