Created
February 27, 2014 13:55
-
-
Save lifedraft/9250476 to your computer and use it in GitHub Desktop.
Update meta viewport tag's content for fit page width. ios and android safe.
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
viewport = document.getElementById('viewport') | |
orientationchange = (event) -> | |
unit = "width" | |
current_orientation = window.orientation | |
wider = window.screen.width > window.screen.height | |
if (current_orientation == 180 and wider) or | |
(current_orientation == 0 and wider) or | |
(current_orientation == -90 and !wider) or | |
(current_orientation == 90 and !wider) | |
unit = "height" | |
unit = window.screen[unit] | |
if (unit > 700) | |
ratio = unit/1032 | |
viewport.setAttribute('content', 'width=1032, initial-scale='+ratio+', maximum-scale=' +ratio + ', user-scalable=yes') | |
else | |
viewport.setAttribute 'content', 'width=device-width, initial-scale=1.0, user-scalable=no' | |
$(window).bind 'orientationchange', orientationchange | |
orientationchange() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment