Catch browser's “zoom” event in JavaScript

前端 未结 16 1596
眼角桃花
眼角桃花 2020-11-22 05:45

Is it possible to detect, using JavaScript, when the user changes the zoom in a page? I simply want to catch a \"zoom\" event and respond to it (similar to window.onresize e

16条回答
  •  -上瘾入骨i
    2020-11-22 05:58

    I'am replying to a 3 year old link but I guess here's a more acceptable answer,

    Create .css file as,

    @media screen and (max-width: 1000px) 
    {
           // things you want to trigger when the screen is zoomed
    }
    

    EG:-

    @media screen and (max-width: 1000px) 
    {
        .classname
        {
              font-size:10px;
        }
    }
    

    The above code makes the size of the font '10px' when the screen is zoomed to approximately 125%. You can check for different zoom level by changing the value of '1000px'.

提交回复
热议问题