移动设备上的Bootstrap 3桌面视图

时间:2015-10-12 05:45:23

标签: php jquery css twitter-bootstrap

我正在尝试在移动视图和平板电脑中显示桌面视图。我用Google搜索并尝试了很多方法,但似乎无法正常工作

Bootstrap 3 - desktop view on a mobile device

How to force desktop view on mobile devices - Bootstrap?

Bootstrap 3 - desktop view on a mobile device

How to show desktop version on mobile screens, in Bootstrap 3?

https://github.com/twbs/bootstrap/issues/13995

我尝试了以下代码

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

首先在HTML头元素中包含标记:

<meta name="viewport" content="width=device-width, initial-scale=1.0">



$(window).resize(function() {
    var mobileWidth =  (window.innerWidth > 0) ? 
                        window.innerWidth : 
                        screen.width;
    var viewport = (mobileWidth > 360) ?
                    'width=device-width, initial-scale=1.0' :
                    'width=1200';
    $("meta[name=viewport]").attr('content', viewport);
}).resize();      

任何人都可以告诉我们如何在最新的bootstrap版本中解决这个问题吗? 谢谢

更新

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script> 
<script>
$(window).resize(function() {
    var mobileWidth =  (window.innerWidth > 0) ? 
                        window.innerWidth : 
                        screen.width;
    var viewport = (mobileWidth > 360) ?
                    'width=device-width, initial-scale=1.0' :
                    'width=1200';
    $("meta[name=viewport]").attr('content', viewport);
}).resize(); 
</script>
</head>
<body>
<div class="bs-example">
    <form>
        <div class="form-group">
            <label for="inputEmail">Email</label>
            <input type="email" class="form-control" id="inputEmail" placeholder="Email">
        </div>
        <div class="form-group">
            <label for="inputPassword">Password</label>
            <input type="password" class="form-control" id="inputPassword" placeholder="Password">
        </div>
        <div class="checkbox">
            <label><input type="checkbox"> Remember me</label>
        </div>
        <button type="submit" class="btn btn-primary">Login</button>
    </form>
</div>
</body>
</html>                

1 个答案:

答案 0 :(得分:1)

你在头部使用两个元标记?如果是这样,plaese删除它:

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

如果没有元标记,请输入:

<meta name="viewport" content="width=device-width, initial-scale=1.0">

...你的JavaScript代码在哪里?在头上:

<script>
  $(window).resize(function() {
    var mobileWidth =  (window.innerWidth > 0) ? 
                        window.innerWidth : 
                        screen.width;
    var viewport = (mobileWidth > 360) ?
                    'width=device-width, initial-scale=1.0' :
                    'width=1200';
    $("meta[name=viewport]").attr('content', viewport);
}).resize(); 
</script>