title: Why element getBoundingClientRect() values condition is not working properly?
body: <p>I have <code>.square</code> element when I move my mouse it should be moved with the mouse. Almost everything is good when I move my mouse normally but when I move my mouse fastly on the right and bottom side, Then the <code>.square</code> box goes to the down or right side and makes the scrollbar.</p>
  <blockquote>
  <p>How can I make my code better than now <strong>OR</strong> How to fix the problem?</p>
  </blockquote>
  <p><strong>[NOTE]:</strong> Transition should have</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>let square = document.querySelector(".square");
  
  document.addEventListener("mousemove", function (e) {
    if (square !== null) {
      let x = e.pageX;
      let y = e.pageY;
  
      square.setAttribute("style", `top: ${y}px; left: ${x}px`);
  
      let getBottom = square.getBoundingClientRect().bottom;
      let getRight = square.getBoundingClientRect().right;
  
      if (getBottom &gt; window.innerHeight) {
        square.setAttribute("style", `bottom: 0; left: ${x}px`);
      }
  
      if (getRight &gt; window.innerWidth) {
        square.setAttribute("style", `top: ${y}px; right: 0`);
      }
  
      if (getRight &gt; window.innerWidth &amp;&amp; getBottom &gt; window.innerHeight) {
        square.setAttribute("style", `bottom: 0; right: 0`);
      }
    }
  });</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>*,
  *::before,
  *::after{
    box-sizing: border-box;
  }
  
  body{
    margin: 0;
    border: 1px solid blue;
  }
  
  .square {
    position: absolute;
    height: 50px;
    width: 50px;
    border: 5px solid red;
    transition: .01s ease-in-out;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="square"&gt;&lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>