LoginSignup
4
5

More than 5 years have passed since last update.

画面を回転しても、viewportを320pxで固定したいとき

Last updated at Posted at 2013-08-02

いろいろ試した結果、ギャラクシーS3とiPhoneがやっかい。

content="width=320"のみ

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

ギャラクシーS3がリキッドのまま。

jQueryでなんとかする

to-Rさんの記事の(2種)を試したら、iPhoneでいまいち。
フォントサイズが小さいまま。(もしかしたら、試したやつなんか間違ってたのかも・・・)
http://blog.webcreativepark.net/2011/01/11-023827.html
http://blog.webcreativepark.net/2012/01/06-110622.html

上の2つをなんとかドッキングすればいいんじゃね?

まずviewportはiPhone向けに書く

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

アンドロイドのときは(ほんとはギャラクシーS3だけでいいんだけど。)、jQueryでviewport上書きつつzoomを指定。

var agent = navigator.userAgent;
if (agent.search(/Android/) !== -1) {
    $('meta[name=viewport]').attr({'content': 'width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no'});
    $(window).bind('resize load', function(){
        $("html").css("zoom" , $(window).width()/320);
    });
}

これでなんとか思いどおりになったと思う。
テストした機種の数少ないので、バグあるかも・・・

ただし注意点が1つ

Androidでスムーズスクロールがずれる。

対処方法

htmlのzoomを取得してoffset().topに掛ける。
参考:androidでjqueryのoffset.top scrollTopがずれる | livedecode.

4
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
5