防止 iPhone 在网络应用程序中放大“选择”
我有这个代码:
<select>
<option value="c">Klassen</option>
<option value="t">Docenten</option>
<option value="r">Lokalen</option>
<option value="s">Leerlingen</option>
</select>
Running in a full-screen web-app on iPhone。
当从此列表中选择某些内容时,iPhone 会放大 select
元素。并且在选择某些内容后不会缩小。
我怎样才能防止这种情况发生?或者缩小回来?
I've got this code:
<select>
<option value="c">Klassen</option>
<option value="t">Docenten</option>
<option value="r">Lokalen</option>
<option value="s">Leerlingen</option>
</select>
Running in a full-screen web-app on iPhone.
When selecting something from this list, the iPhone zooms in on the select
-element. And doesn't zoom back out after selecting something.
How can I prevent this? Or zoom back out?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(12)
可能是因为字体大小小于阈值,浏览器试图缩放该区域,这种情况通常发生在iphone中。
赋予元标签属性“user-scalable=no”将限制用户在其他地方缩放。由于问题仅与 select 元素有关,请尝试在 css 中使用以下内容,此 hack 最初用于 jquery mobile。
HTML :
CSS:
src: 在 iphone 中选择后取消缩放
It is probably because the browser is trying to zoom the area since the font size is less than the threshold, this generally happens in iphone.
Giving a metatag attribute "user-scalable=no" will restrict the user from zooming elsewhere. Since the problem is with select element only, try using the following in your css, this hack is originally used for jquery mobile.
HTML :
CSS:
src: unzoom after selecting in iphone
user-scalable=no 是您所需要的,这样这个问题实际上就有了明确的答案
user-scalable=no is what you need, just so there's actually a definitive answer to this question
如果文本设置为小于 16 像素,iPhone 会稍微缩放表单字段。我建议将移动表单字段的文本设置为 16 像素,然后覆盖桌面尺寸。
说禁用缩放的答案对于可访问性没有帮助/视力不佳的用户可能仍然希望在较小的手机上缩放。
例子:
iPhone's will zoom form fields slightly if the text is set to less than 16 pixels. I'd suggest setting the mobile form field's text to be 16 pixels and then override the size back down for desktop.
The answers saying to disable zoom are unhelpful for accessibility / partially sighted users may still want to zoom on smaller mobiles.
Example:
这似乎适用于我解决此问题的情况:
建议此处作者:克里斯蒂娜·阿拉斯莫·贝梅尔
This seemed to work for my case in addressing this issue:
Suggested here by Christina Arasmo Beymer
我来晚了一点,但我发现了一个非常巧妙的解决方法,仅通过 css 操作即可解决此问题。就我而言,由于设计原因,我无法更改字体大小,也无法禁用缩放。
由于如果文本设置为小于 16 像素,iPhone 会稍微缩放表单字段,因此我们可以欺骗 iPhone 认为字体大小是 16px,然后将其转换为我们的大小。
例如,当我们的文本为 14px 时,它会缩放,因为它小于 16px。因此我们可以根据0.875变换尺度。
在下面的示例中,我添加了填充以展示如何相应地转换其他属性。
我希望它有帮助!
I am a bit late to the party, but I found a pretty neat workaround that solves this issue only with css manipulation. In my case I couldn't change the font size due to design reasons, and I couldn't disable zooming as well.
Since iPhone's will zoom form fields slightly if the text is set to less than 16 pixels, we can trick the iPhone to think that the font size is 16px and then transform it to our size.
For example, lets take the example when our text is 14px, so it does zoom because it is smaller than 16px. Therefore we can transform the scale, according to 0.875.
In the following example I've added the padding to show how to convert other properties accordingly.
I hope it helps!
如果字体大小小于 16 像素,iOS 会缩放页面以显示更大的输入字段。
仅在单击任何字段时,才会缩放页面。所以点击时,我们将其设置为 16px,然后更改为默认值
下面的代码片段对我来说效果很好,并且针对移动设备,
iOS zooms the page to show a larger input field if its font-size is less than 16px.
only On click of any field, it's zooming the page. so on click, we are making it as 16px and then changed to default value
below snippet works fine to me and targeted for mobile devices,
试试这个:
DisablePinchZoom 将在 onchange 之前触发,因此缩放将在 onchange 触发时禁用。
在onchange函数上,最后可以恢复初始情况。
在 iPhone 5S 上测试
Try this:
DisablePinchZoom will be fired before the onchange so zoom will be disable at the time the onchange is fired.
On the onchange function, at the end you can restore the initial situation.
Tested on an iPhone 5S
将所有“选择”字体大小设置为 16px
select{
字体大小:16px;
}
Set all 'select' font size to 16px
select{
font-size: 16px;
}
我认为你不能孤立地对这种行为采取任何行动。
您可以尝试的一件事是完全阻止页面缩放。如果您的页面是为手机设计的,那么这很好。
您可以尝试的另一件事是使用 JavaScript 构造而不是通用的“select”语句。创建一个隐藏的 div 来显示您的菜单,在 javascript 中处理点击。
祝你好运!
I don't think you can't do anything about the behavior in isolation.
One thing you can try is keep the page from zooming at all. This is good if your page is designed for the phone.
Another thing you could try is using a JavaScript construct instead of the generic "select" statement. Create a hidden div to show your menu, process the clicks in javascript.
Good luck!
正如此处回答的: 禁用自动缩放输入“文本”标签 - iPhone 上的 Safari
您可以阻止 Safari 在用户输入期间自动放大文本字段,无需禁用用户的捏缩放的能力。只需添加
maximum-scale=1
但忽略其他答案中建议的用户规模属性。如果图层中的表单在缩放时会“浮动”,那么这是一个值得选择的选项,这可能会导致重要的 UI 元素移出屏幕。
As answered here: Disable Auto Zoom in Input "Text" tag - Safari on iPhone
You can prevent Safari from automatically zooming in on text fields during user input without disabling the user’s ability to pinch zoom. Just add
maximum-scale=1
but leave out the user-scale attribute suggested in other answers.It is a worthwhile option if you have a form in a layer that “floats” around if zoomed, which can cause important UI elements to move off screen.
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
尝试添加此 CSS 以禁用 Ios 的默认样式:
这也适用于获得特殊样式的其他元素,例如 input[type=search]。
Try adding this CSS to disable Ios' default styling:
This will also work on other elements that get special styling, like input[type=search].
已经阅读了几个小时,最好的解决方案是这里的 jquery。这也有助于 iOS Safari 中的“下一个选项卡”选项。我在这里也有输入,但您可以随意删除或添加您喜欢的内容。基本上,mousedown 在焦点事件之前触发,并欺骗浏览器认为它是 16px。此外,焦点将在“下一个选项卡”功能上触发并重复该过程。
Been reading for a few hours on this and the best solution is this jquery here. This also helps with the "next tab" option in iOS Safari. I have inputs here as well but feel free to remove them or add as you like. Basically the mousedown fires before the focus event and tricks the browser into thinking its 16px. In addition, the focusout will trigger on the "next tab" feature and repeat the process.