Skip to content

Instantly share code, notes, and snippets.

@trixter5
Created November 30, 2017 07:46
Show Gist options
  • Save trixter5/201fdea3af10018b2a4cb0d29c5aef9f to your computer and use it in GitHub Desktop.
Save trixter5/201fdea3af10018b2a4cb0d29c5aef9f to your computer and use it in GitHub Desktop.
// Store the meta element
var viewport_meta = document.getElementById('viewport-meta');
// Define our viewport meta values
var viewports = {
default: viewport_meta.getAttribute('content'),
landscape: 'width=640'
};
// Change the viewport value based on screen.width
var viewport_set = function() {
if ( screen.width < 767 )
viewport_meta.setAttribute( 'content', viewports.landscape );
else
viewport_meta.setAttribute( 'content', viewports.default );
}
// Set the correct viewport value on page load
viewport_set();
// Set the correct viewport after device orientation change or resize
window.onresize = function() {
viewport_set();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment