我遇到一个问题,当我将网页从纵向旋转到横向(例如在iOS设备上 - 例如iPhone5)时,横向视图从页面顶部开始大约50px。向后旋转显示纵向视图没有问题。
以下是显示问题的屏幕截图:
肖像(正确):
旋转后的风景(不正确):
Lanscape应该如何显示:
如果您想在设备上查看链接本身,请参阅以下链接:
答案 0 :(得分:3)
经过一番挖掘后,这里的代码可以在旋转到移动设备上的横向视图时滚动到顶部:
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);
}
};