zoukankan      html  css  js  c++  java
  • jquery尺寸:宽度与高度

      width() 方法设置或返回元素的宽度(不包括内边距、边框或外边距)。

      height() 方法设置或返回元素的高度(不包括内边距、边框或外边距)。

      innerWidth() 方法返回元素的宽度(包括内边距)。

      innerHeight() 方法返回元素的高度(包括内边距)。  

      outerWidth() 方法返回元素的宽度(包括内边距和边框)。

      outerHeight() 方法返回元素的高度(包括内边距和边框)。

      outerWidth(true) 方法返回元素的宽度(包括内边距、边框和外边距)。

      outerHeight(true) 方法返回元素的高度(包括内边距、边框和外边距)。

      $(document).width()与$(window).width()返回文档(HTML 文档)和窗口(浏览器视口)的宽度和高度。

     1 <!DOCTYPE html>
     2 <html>
     3 <head>
     4 <meta charset="utf-8" />
     5 <title></title>
     6 <link rel="stylesheet" href="css/all.css" />
     7 <style type="text/css">
     8 div { margin: 10px; padding: 10px; width: 300px; height: 200px; border: 10px solid #ccc; }
     9 </style>
    10 <script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
    11 <script type="text/javascript" src="js/all.js"></script>
    12 </head>
    13 
    14 <body>
    15 <div></div>
    16 <div></div>
    17 <div></div>
    18 <div></div>
    19 <div></div>
    20 <div></div>
    21 <div></div>
    22 <div></div>
    23 <div></div>
    24 </body>
    25 </html>
    26 <script type="text/javascript">
    27     var s1 ='width()是' + $('div').width() +'px,因为width()不包含margin,padding,border';
    28     var s2 ='innerWidth()是' + $('div').innerWidth() +'px,因为包含了padding,左右各10px';
    29     var s3 ='outerWidth()是' + $('div').outerWidth() +'px,因为包含了padding(左右名10px)与border(左右名10px)';
    30     var s4 ='outerWidth(true)是' + $('div').outerWidth(true) +'px,包含了padding,margin,border,左右名10px';
    31     var s5 ='document文档的width()是' + $(document).width() +'px';
    32     var s6 ='window窗口的width()是' + $(window).width() +'px';
    33     alert(s1);
    34     alert(s2);
    35     alert(s3);
    36     alert(s4);
    37     alert(s5);
    38     alert(s6);
    39     alert('当没有垂直滚动条的时候,$(document).width()与$(window).width()在我的电脑上的宽度是1366,而在有垂直滚动条的时候,在我的电脑上的宽度是1349。并且当调整浏览器窗口的大小的时候,这两个值也会相应的发生变化。');
    40 </script>
  • 相关阅读:
    [转载] <深入理解.NET> 导读
    32bit Assembler is Easy, why and how to develop using the assembler; start learning to program in Assembly now!
    一致代码段,非一致代码段
    Data Mining、Data Warehousing、OLAP三者关系 [收藏]
    对比Windows和Linux两系统的动态库
    Win32汇编开发环境介绍和RadAsm简明教程
    How to make a 32 bit protected mode boot sector.
    龙芯CPU 参数
    并发编程第一章简单介绍和环境准备
    并发编程第三章线程创建、原理、常用线程方法
  • 原文地址:https://www.cnblogs.com/darkterror/p/5007719.html
Copyright © 2011-2022 走看看