Created
July 5, 2016 03:21
-
-
Save tonpoo/51763cc862d59271f6055060d177e955 to your computer and use it in GitHub Desktop.
画面の横幅に応じてmeta viewportの値を動的に変更するjs(要jquery)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 画面の横幅に応じてmeta viewportの値を動的に変更するjs(要jquery) | |
* | |
* window.screen.widthの値を見て$("meta[name='viewport']").attr("content", "xxxxxxxxxx")で設定 | |
*/ | |
$(window).on("resize orientationchange", function (e) { | |
var wsw = window.screen.width; | |
if (wsw <= 640) { | |
//デバイス横幅640以下 | |
$("meta[name='viewport']").attr("content", "width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no,shrink-to-fit=no"); | |
} else if (wsw < 980) { | |
//デバイス横幅980より下 | |
$("meta[name='viewport']").attr("content", "width=980px,user-scalable=0,shrink-to-fit=no"); | |
} else { | |
//それ以外 | |
$("meta[name='viewport']").attr("content", "width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no,shrink-to-fit=no"); | |
} | |
}).trigger("resize"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment