jquery $(window).width() and $(window).height() return different values when viewport has not been resized

前端 未结 4 700
野性不改
野性不改 2020-12-04 07:45

I am writing a site using jquery that repeatedly calls $(window).width() and $(window).height() to position and size elements based on the viewport

4条回答
  •  离开以前
    2020-12-04 08:13

    I think what you're seeing is the hiding and showing of scrollbars. Here's a quick demo showing the width change.

    As an aside: do you need to poll constantly? You might be able to optimize your code to run on the resize event, like this:

    $(window).resize(function() {
      //update stuff
    });
    

提交回复
热议问题