is there anyway to manipulate viewport in javacript?

Viewed 129

I've been trying to figure it out using javascript to modify viewport scale and its properties. after checking visualViewport API they are all read-only data. is there any way to dynamically control viewport? like scaling up or setting position of viewport. I want to scale up the viewport as if I were a pinch zoom using javascript.

I already check similar way to handle above by using meta-tag. but I need the functionality after initialization. also viewport should be moved.

1 Answers

This Snippet might help you.

// 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=990'
    };

// Change the viewport value based on screen.width
var viewport_set = function() {
        if ( screen.width > 768 )
            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(); 
}

Related