This repository was archived by the owner on Mar 19, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
EndlessRunnerGameKit/WebGL Builds Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change 1+ < style >
2+ .landscape-screen {
3+ transform-origin : top left;
4+ transform : rotate (90deg ) translateY (-100% )
5+ }
6+ </ style >
7+ < iframe id ="Frame " style ="Frame " src ="game.html "> </ iframe >
8+ < script >
9+ var orientation = window . orientation ;
10+
11+ //开始时调用
12+ var Frame = document . getElementById ( "Frame" ) ;
13+ if ( orientation == 180 || orientation == 0 || orientation == - 180 ) {
14+ //注意竖屏时要把 iframe的宽设置为当前窗口的高度 高设置为当前窗口的宽度
15+ Frame . height = window . innerWidth ;
16+ Frame . width = window . innerHeight ;
17+
18+ //通过css样式旋转90度
19+ Frame . classList . add ( "landscape-screen" ) ;
20+ } else {
21+ //横屏时则正常
22+ Frame . height = window . innerHeight ;
23+ Frame . width = window . innerWidth ;
24+
25+ //通过移除类去掉css样式
26+ Frame . classList . remove ( "landscape-screen" ) ;
27+ }
28+
29+ //监听手机旋转事件 根据旋转状态设置旋转的css样式
30+ window . onorientationchange = function ( ) {
31+ if ( orientation == 180 || orientation == 0 || orientation == - 180 ) {
32+ Frame . classList . add ( "landscape-screen" ) ;
33+ } else {
34+ Frame . classList . remove ( "landscape-screen" ) ;
35+ }
36+ } ;
37+ </ script >
You can’t perform that action at this time.
0 commit comments