1 创建video 标签,标签设置属性 autoplay 自动播放,宽高100 全屏。
<video class="video" id="shipin" controls="controls" autoplay poster="" style="width:100%;height:100%;position:fixed;"><source src="" type="video/mp4" />
</video>
2 js监听 按键执行方法
window.document.onkeydown = function (e) {//console.log(e)//alert("你按键//key:" + e.key + "-keyCode:" + e.keyCode);if (e.keyCode == 13) {if (myVideo.paused) {myVideo.play();} else {myVideo.pause();}}}
3 myVideo.play(); 播放 myVideo.pause();暂停