Computer >> Máy Tính >  >> Lập trình >> Javascript

Việc sử dụng sự kiện onresize trong JavaScript là gì?

Sự kiện thay đổi kích thước được kích hoạt khi cửa sổ được thay đổi kích thước. Sử dụng window.outerWidth window.outerHeight sự kiện trong JavaScript để lấy kích thước của cửa sổ khi trình duyệt được thay đổi kích thước.

Ví dụ

Bạn có thể thử chạy mã sau để làm việc với sự kiện kích thước lớn trong JavaScript.

<!DOCTYPE html>
<html>
   <head>
      <script>
         function resizeFunction() {
            var val = "Window Width=" + window.outerWidth + ", Window Height=" + window.outerHeight;
            document.getElementById("test").innerHTML = val;
         }
      </script>
   </head>
   <body onresize="resizeFunction()">
      <p>Resize browser window and check the window (browser window) height and width again.</p>
     
      <p id = "test"> </p>
   </body>
</html>