Last active
January 5, 2019 18:25
-
-
Save crazyyy/d559dd29152b0edce1c579f09d466810 to your computer and use it in GitHub Desktop.
#js #jquery || width of screen on mobile
This file contains hidden or 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 content="user-scalable=yes, maximum-scale=1.6, width=device-width, initial-scale=1, target-densitydpi=device-dpi" name="viewport"> |
This file contains hidden or 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
function mobileFriendly() { | |
setTimeout(function() { | |
if (/Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent)) { | |
var ww = (document.documentElement.clientWidth < window.screen.width) ? jQuery(window).width() : window.screen.width; //get proper width | |
var mw = 725; | |
//alert ("width" + ww); | |
var ratio = ww / mw; //calculate ratio | |
//alert ("ratio: " + ratio); | |
if (ratio < 1) { //smaller than minimum size | |
jQuery("meta[name='viewport']").attr('content', 'initial-scale=' + ratio + ', maximum-scale=' + ratio + ', minimum-scale=' + ratio + ', user-scalable=yes, width=' + mw); | |
} else { //regular size | |
jQuery("meta[name='viewport']").attr('content', 'initial-scale=1.0, maximum-scale=2, minimum-scale=1.0, user-scalable=yes, width=' + ww); | |
} | |
} | |
}, 600); | |
} | |
jQuery(document).ready(function() { | |
mobileFriendly() | |
}); | |
window.addEventListener("orientationchange", mobileFriendly, false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment