HTML5 中的 Web 音频与 SVG 技术详解
1. 游戏启动函数
在网页开发中,有时候需要实现游戏启动的功能。以下是一个简单的游戏启动函数示例:
function startGame() {
// Keep the game from starting more than once
if (!isPlaying) {
// Register input handlers
document.body.addEventListener("keyup", doOnKeyUp);
document.body.addEventListener("keydown", doOnKeyDown);
// Reposition the bowl lid
var bowlTop = document.querySelector("#bowl-top");
bowlTop.classList.remove("bowl-closed");
bowlTop.style.left = (event.screenX - bowlTop.offsetWidth + 65) + "px";
bowlTop.style.top = (event.screenY - bowlTop.offsetHeight + 65 * 0) + "px";
// Disable dragging on the lid by removing the HTML5 draggable
attribute
bowlTop.removeAttribute("draggable");