Example of jQuery Listening Browser Window Size Change
- 2021-07-16 01:36:56
- OfStack
Method 1: Add onLoad= "" onResize= "" method to the label and write the corresponding method
Method 2: window. onresize=function () {///......} Just write the corresponding code in the method
Both methods can basically solve the problem.
<script>
function adjust(obj){
var div = document.getElementById("pad");
var txt = document.getElementById("txt");
var w = document.body.clientWidth;
var h = document.body.clientHeight;
div.style.width = w/3;
div.style.height = h/3;
txt.style.width = w/6;
txt.style.height = h/6;
}
window.onload=function(){
window.onresize = adjust;
adjust();
}
</script>
<body style="margin:0px;height:0px;">
<div id="pad" style="background:red;zoom:1;margin:0px;height:0px;">
<input type="text" id="txt">
</div>
</body>