본문 바로가기
IT/JavaScript와 Framework

jQuery window bind resize event 예제

by 골든크랩 2022. 5. 4.
728x90
반응형

출처 : http://www.java2s.com/ref/javascript/jquery-window-bind-resize-event.html

 

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Executing a Function on Resize Event in jQuery</title>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<style>
    p{/* w ww  .j av a  2  s  .  com*/
        padding: 20px;
        font: 20px sans-serif;
        background: #f0e68c;
    }
</style>
<script>
$(document).ready(function(){
    $(window).resize(function() {
        $(window).bind("resize", function(){
            $("p").text("Window width: " + 
                  $(window).width() + 
                  ", " + 
                  "Window height: " + 
                  $(window).height());
        });
    });
});
</script>
</head>
<body>
    <p>resize the browser window by dragging the corners.</p>
</body>
</html>
728x90
반응형

댓글