Force mobile browser zoom out with Javascript

前端 未结 5 1778
名媛妹妹
名媛妹妹 2020-12-03 17:26

In my web app, I have some thumbnails that open a lightbox when clicked. On mobile, the thumbnails are small and the user typically zooms in. The problem is that when they c

5条回答
  •  独厮守ぢ
    2020-12-03 18:20

    Similar to Radley Sustaire's solution I managed to force unzoom whenever the device is turned in React with

      zoomOutMobile = () => {
        const viewport = document.querySelector('meta[name="viewport"]');
    
        if ( viewport ) {
          viewport.content = 'initial-scale=1';
          viewport.content = 'width=device-width';
        }
      }
    

    and inside my render

    this.zoomOutMobile();
    

    1 edge case I found was this did not work on the Firefox mobile browser

提交回复
热议问题