启动全屏functionlaunchFullscreen(element){if(element.requestFullscreen){element.requestFullscreen();}elseif(element.mozRequestFullScreen){element.mozRequestFullScreen();}elseif(element.webkitRequestFullscreen){element.webkitRequestFullscreen();}elseif(element.msRequestFullscreen){element.msRequestFullscreen();}}现在这段代码只能点击按钮才能全屏,有没有什么方法自动全屏浏览器的请给出代码实现谢谢
2 回答
茅侃侃
TA贡献1842条经验 获得超21个赞
我试着改写成立即执行的函数表达式:(functionlaunchFullscreen(element){if(element.requestFullscreen){element.requestFullscreen();}elseif(element.mozRequestFullScreen){element.mozRequestFullScreen();}elseif(element.webkitRequestFullscreen){element.webkitRequestFullscreen();}elseif(element.msRequestFullscreen){element.msRequestFullscreen();}})(document.documentElement);但是chrome提示:Failedtoexecute'requestFullScreen'on'Element':APIcanonlybeinitiatedbyausergesture.貌似意设定:这种api操作只能有人来出发。。。api给的例子也是由一个条件来出发这个html5的全屏函数:element.requestFullScreen()Makesanindividualelementfull-screen,e.g.document.getElementById(“myvideo”).requestFullScreen().
12345678_0001
TA贡献1802条经验 获得超5个赞
试试把宽高设置成100%,或者设置成window.screen.availHieght和window.screen.availWidth
添加回答
举报
0/150
提交
取消