Can I trigger a CSS event in mobile safari upon iphone orientation change?

后端 未结 6 2240
别那么骄傲
别那么骄傲 2020-12-03 14:12

I\'m trying to figure out how to change an embedded web page when the user rotates their phone from portrait to landscape mode - basically to load a view that is better suit

6条回答
  •  南笙
    南笙 (楼主)
    2020-12-03 14:36

    Best not to set the onorientationchange property directly. Instead use the following:

    window.addEventListener('orientationchange', function (evt) {
        switch(window.orientation) {
            case 0: // portrait
            case 180: // portrait
            case 90: // landscape
            case -90: // landscape
        }
    }, false);
    

提交回复
热议问题