jquery獲取瀏覽器客戶區尺寸程式碼例項

admin發表於2017-04-07

本章節分享一段程式碼例項,它實現了獲取瀏覽器客戶區的功能。

關於什麼是瀏覽器客戶區可以參瀏覽器客戶區是指的瀏覽器哪一部分一章節。

程式碼例項如下:

[HTML] 純文字檢視 複製程式碼
<!DOCTYPE html>
<html> 
<head> 
<meta charset=" utf-8"> 
<meta name="author" content="http://www.softwhy.com/" /> 
<title>螞蟻部落</title>
<style>
#antzone,#show{
  width:200px;
  height:100px;
  margin:0px auto;
}
</style>
<script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script> 
<script type="text/javascript">
$(window).resize(function(){
  var str="";
  str=str+"高度是:"+$(window).height();
  str=str+"寬度是:"+$(window).width();
  $("#show").text(str);
})
</script> 
</head>
<body>
<div id="antzone">調整瀏覽器大小檢視效果</div>
<div id="show"></div>
</body>
</html>

上面的程式碼演示了獲取瀏覽器客戶區大小的功能。

resize事件可以參閱jQuery resize 事件一章節。

相關文章