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

后端 未结 6 2227
别那么骄傲
别那么骄傲 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:21

    You can use the window.orientation property. Its value is the degree that the current mode of view is used. Here is a brief example:

    function updateOrientation()
    {   
        var orientation=window.orientation;
        switch(orientation)
        {
    
            case 0:
    
                    break;  
    
            case 90:
                    break;
    
            case -90:   
    
                    break;
        }
    
    }
    

    You can use this function on this event:

    window.onorientationchange=updateOrientation;
    

    Hope that helps!

提交回复
热议问题