简体   繁体   English

如何使我的简单网站测验适合平板电脑和手机?

[英]How to make my simple website-quiz fittable to tablets and mobile phones?

how could I make my simple website-quiz fittable to tablets and mobile phones? 如何使我的简单网站测验适合平板电脑和手机? The size of the quiz is 1024x672 in landscape mode. 在横向模式下,测验的大小为1024x672。 The size is static. 大小是静态的。 If there's no bullet-proof solution for all devices, I would prefer a solution specific for iPhones and iPads. 如果没有针对所有设备的防弹解决方案,我希望使用专门针对iPhone和iPad的解决方案。

Here's the quiz: http://wp.servitus.ch 这是测验: http : //wp.servitus.ch

Requirements: 要求:

  • auto-zoom dependent of current screen-size of the device 自动缩放取决于设备当前的屏幕尺寸
  • user should not be able to zoom manually 用户应该无法手动缩放
  • possible to force landscape mode ? 可以强制使用风景模式吗?

I already experimented with: 我已经尝试过:

<meta name="viewport" content="initial-scale=1,user-scalable=no,maximum-scale=1,width=device-width">

This works fine for iPads, but is way too large on the iPhone. 这在iPad上工作正常,但在iPhone上太大了。

Any ideas ? 有任何想法吗 ?

This meta viewport can't help you, as the initial-scale is 1. That's why it's way too big for iPhone: you tell the device that the initial scale of this page must be 100% of its size (here : 1024px width), you have to remove this parameter or set it lower (0.5 or 0.625, as 640/1024 = 0.625). 此meta视口无法帮助您,因为initial-scale为1。这就是为什么它对于iPhone太大的原因:您告诉设备此页面的初始比例必须是其尺寸的100%(此处为1024px宽度) ,则必须删除此参数或将其设置为较低(0.5或0.625,因为640/1024 = 0.625)。

Try with (this should work for iPhone and iPad) : 尝试一下(这适用于iPhone和iPad):

<meta name="viewport" content="width=device-width">

or (this should be very small on iPad) : 或者(在iPad上应该很小):

<meta name="viewport" content="initial-scale=0.6,user-scalable=no,maximum-scale=1,width=device-width">

EDIT : 编辑:

This should work : 这应该工作:

<meta name="viewport" content="width=1024">

I used that trick on a mobile website that haven't been well coded, it forces the viewport to 1024 and make it fit in the device screen. 我在没有经过良好编码的移动网站上使用了该技巧,它将视口强制设置为1024,并使其适合设备屏幕。 You can add whatever parameters to the meta. 您可以向meta添加任何参数。

Currently I am using the code below. 目前,我正在使用下面的代码。 This meets my requirements for the moment (distinction between iPad, iPhone, Computer). 目前可以满足我的要求(iPad,iPhone,计算机之间的区别)。 If anyone has a bullet-proof solution for all possible devices, I would be glad if you would share it with me :-) Thanks! 如果有人对所有可能的设备都拥有防弹解决方案,那么如果您能与我分享它,我将非常高兴:-)谢谢!

$(document).ready(function() {

    var isMobile = (/iPhone|iPod|Android|BlackBerry/).test(navigator.userAgent);
    var isTablet = (/iPad/).test(navigator.userAgent);

    if(isMobile) {
        $('<meta name="viewport" content="initial-scale=0.45, maximum-scale=0.45, width=device-width, user-scalable=yes">').appendTo('head');
    } else if(isTablet) {
        $('<meta name="viewport" content="initial-scale=0.95, maximum-scale=0.95, width=device-width, user-scalable=no">').appendTo('head');
    } else {
        $('<meta name="viewport" content="initial-scale=1, maximum-scale=1, width=device-width, user-scalable=no">').appendTo('head');
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM