jQuery移动设备扩展 [英] JQuery Mobile Device Scaling
问题描述
我正在使用JQuery Mobile,但无法将浏览器缩放到iPhone.
I am using JQuery Mobile and I am having trouble with the scaling from my browser to my iPhone.
当我将其加载到浏览器(野生动物园)中时,它会缩小和扩展.但是,当我将其加载到iPhone上时,它无法缩放.它可以让您在不应该的时候向左和向右滚动.
When I load it on a browser (safari) it shrinks and expands just fine. However when I load it on my iPhone it doesn't scale. It allows you to scroll left and right when it shouldn't.
是否应该添加一些内容以使其缩小以识别它是移动设备.
Is there something I am supposed to add to make it scale down on recognize that it's a mobile device.
这是我当前的html.
Here is my current html.
<head>
<title>Page Title</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://www.domain.com/css/jquery.mobile-1.0b1.min.css" />
<link rel="stylesheet" href="http://www.domain.com/css/base.css" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.1.min.js">
</script>
<script type="text/javascript" src="http://code.jquery.com/mobile/1.0b1/jquery.mobile-1.0b1.min.js"></script>
</head>
<body>
<body>
<!-- Start of first page -->
<div data-role="page">
<div data-role="header">
<div id="header">
<ul>
<li>
<div><a href="logout.php">Logout</a>
</div>
</li>
<li style="float:right;">
<div><a href="new.php">New</a>
</div>
</li>
<h1 align="center">Title</h1>
</ul>
<div id="clear"></div>
</div>
</div>
<!-- /header -->
<div id="stream">
<div id="stream_story">
<ul style="width:100%">
<li>
<img src="" />
</li>
<li style="float:right;">></li>
<li style="width:75%;margin-bottom:10px;margin-left:5px;">Content
<br/><span>Content</span>
</li>
</ul>
</div>
<div id="clear"></div>
<hr/>
</div>
<!-- /content -->
</div>
<!-- /page -->
</body>
</body>
</html>
推荐答案
我在iPhone视口和JQuery-Mobile上也遇到了问题,最终得到了以下解决方案.
I had problems with the iPhone viewport and JQuery-Mobile as well, I ended up with the following solution.
- 添加一个将高度和宽度设置为device-height/device-width的元标记(您可以通过将最大比例更改为大于1来允许用户缩放,但是在以下示例中禁用了缩放,相信Mobile Safari最多可以输入10):
<meta name="viewport" content="height=device-height,width=device-width,initial-scale=1.0,maximum-scale=1.0" >
- 当用户更改iPhone上的方向时,我注意到重新缩放和添加空格后出现了一些奇怪的行为,所以我使用了以下代码:
//check the navigator.userAgent string to detect if the user is using an iPhone
if (navigator.userAgent.match(/iPhone/i)) {
//cache the viewport tag if the user is using an iPhone
var $viewport = $('head').children('meta[name="viewport"]');
//bind an event handler to the window object for the orientationchange event
$(window).bind('orientationchange', function() {
if (window.orientation == 90 || window.orientation == -90 || window.orientation == 270) {
//landscape
$viewport.attr('content', 'height=device-width,width=device-height,initial-scale=1.0,maximum-scale=1.0');
} else {
//portrait
$viewport.attr('content', 'height=device-height,width=device-width,initial-scale=1.0,maximum-scale=1.0');
}
//trigger an orientationchange event on the window object to initialize this code (basically in-case the user opens the page in landscape mode)
}).trigger('orientationchange');
}
事件处理程序中的if/then语句检查用户更改了哪个方向(90,-90和270都是我为横向所见的值),而$viewport.attr('content',...
行仅切换了高度和视口标记中的宽度值.
The if/then statement in the event handler checks for which orientation the user has changed to (90, -90, and 270 are all values I've seen for landscape) and the $viewport.attr('content',...
lines just switch the height and width values in the viewport tag.
这篇关于jQuery移动设备扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!