簡體   English   中英

<a>鏈接和:當我包含某個 JavaScript 文件時,hover 事件不起作用</a>

[英]<a> links and :hover events not working when I include a certain JavaScript file

我正在為我的網站制作導航欄。 為了開發它,我創建了一個新的 HTML 文件,這樣我就可以在不更改主 index.html 文件的情況下使用代碼。 在其自己的 HTML 文件中,所有鏈接和 hover 事件都在工作。 However, when I brought the header code into my working index.html file, the links do not work, and the:hover css events no longer work. 我將問題縮小到包含 Javascript 文件。 這個 javascript 文件控制蛇游戲的元素,並包含一個遞歸運行的 requestAnimationFrame 游戲循環。

如何阻止此 JS 文件阻止這些其他事件?

這是游戲循環...

function main(currentTime) {

    if (gameOver) {
        if (confirm("You lost. Press ok to restart.")) {
            window.location ="/"
        }
        return
    }

    window.requestAnimationFrame(main)
    const secondsSinceLastRender = (currentTime - lastRenderTime) / 1000;
    if (secondsSinceLastRender < 1 / SNAKE_SPEED) return
    
    // console.log("Render")
    lastRenderTime = currentTime
    
    update()
    draw()
}

window.requestAnimationFrame(main)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM