更改浏览器大小时,将触发jQuery resize()事件,并且此事件仅绑定到$(window) 。
$(window).resize(function () {
$('#msg').text('Browser (Width : ' + $(window).width()
+ ' , Height :' + $(window).height() + ' )');
});
要获取浏览器的宽度和高度详细信息,请使用$(window).width()和$(window).height() 。
自己尝试
<html>
<head>
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<style type="text/css">
#browserInfo{
padding:8px;
border:1px solid blue;
width:300px;
}
</style>
</head>
<body>
<h1>jQuery resize() example</h1>
<h2>Try resize this browser</h2>
<div id="browserInfo">
</div>
<script type="text/javascript">
$('#browserInfo').text('Browser (Width : '
+ $(window).width() + ' , Height :' + $(window).height() + ' )');
$(window).resize(function () {
$('#browserInfo').text('Browser (Width : ' + $(window).width()
+ ' , Height :' + $(window).height() + ' )');
});
</script>
</body>
</html>