Press left and right arrow to change image?

后端 未结 3 1596
庸人自扰
庸人自扰 2021-01-03 10:14

So I have this simple slideshow:

\"slideshow\"
3条回答
  •  半阙折子戏
    2021-01-03 10:52

    You can detect arrow key presses in JavaScript and then attach each key to an event. This SO answer shows how it's done but essentially:

    document.onkeydown = checkKey;
    
    function checkKey(e) {
    
        e = e || window.event;
    
        if (e.keyCode == '37') {
            // left arrow
        }
        else if (e.keyCode == '39') {
            // right arrow
        }
    }
    

提交回复
热议问题