【问题标题】:Scroll Webpage to Top on Mobile Device when Rotated旋转时将网页滚动到移动设备上的顶部
【发布时间】:2014-06-20 12:29:03
【问题描述】:

我遇到了一个问题,当我的网页从纵向旋转到横向时(例如在 iOS 设备上 — iPhone5),横向视图从页面顶部开始大约 50 像素。向后旋转可以毫无问题地显示纵向视图。

以下是显示问题的屏幕截图:

纵向(正确):

旋转后的风景(不正确):

Lanscape 应该如何显示:

如果您想在设备上查看,这里是链接本身:

http://bit.ly/1ukGNbB

【问题讨论】:

标签: html css twitter-bootstrap


【解决方案1】:

经过一番挖掘,下面是在移动设备上旋转到横向视图时允许滚动到顶部的代码:

window.onorientationchange = function () {

    var orientation = window.orientation;

    // Look at the value of window.orientation:

    if (orientation === 0) {

        // device is in Portrait mode.

    } else if (orientation === 90) {

        // device is in Landscape mode. The screen is turned to the left.

        $('body').animate({
            scrollTop: '0'
        }, 0);

    } else if (orientation === -90) {

        // device is in Landscape mode. The screen is turned to the right.

        $('body').animate({
            scrollTop: '0'
        }, 0);

    }

};

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-01-02
    • 2011-03-30
    • 2022-12-09
    • 1970-01-01
    • 2016-05-06
    • 2019-08-22
    • 2017-03-04
    相关资源
    最近更新 更多