2

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.

05park
  • 21
  • 3
  • 2
    It sounds like you should [explain what you actually want to do](/help/how-to-ask) that you think requires viewport access. Because this feels like an [XY Problem](https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem) right now. – Mike 'Pomax' Kamermans Jul 20 '21 at 04:02

1 Answers1

1

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(); 
}