美文网首页
17、宽高

17、宽高

作者: 一直流浪 | 来源:发表于2022-09-01 12:27 被阅读0次

获取宽高的几种方式:

  • css('height') / css('width')
    • 获取组件的宽高,带有px,是字符串
  • width(),height()
    • 获取或设置宽高,不包括padding/border/margin
  • innerWidth()/innerHeight()
    • 方法返回元素 的宽度/高度(包括内边距padding)
  • outerWidth()/outerHeight
    • 方法返回元素 的宽度/高度(包括内边距padding和边框border)
  • outerWidth(true)/outerHeight(true)
    • 方法返回元素 的宽度/高度(包括内边距padding和边框border和外边框margin)
  • (window).width() /(window).height()
    • 获取页面可视区域的宽高

案例代码:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <style>
            .one{
                width:200px;
                border: 10px solid red;
                padding: 20px;
                margin: 30px;
            }
        </style>
    </head>
    <body>
        <input type="button" value="按钮" id="btn" />
        <div id="one" class="one" style="height: 200px;"></div>
    </body>
</html>

<script type="text/javascript" src="js/jQuery.js" ></script>
<script>
    $(function(){
        $('#btn').click(function(){
            //1.1 css('height'),css('width')
            //获取id为one的宽高,带有px,是字符串
//          console.log($('#one').css('height'));
//          console.log($('#one').css('width'));
            
            //1.2width(),height()  
            //获取或设置宽高,不包括padding/border/margin
            //(1)获取宽高
//          console.log($('#one').width());
//          console.log($('#one').height());
            
            //(2)设置宽高
//          $('#one').width(300);
//          $('#one').height(300);
            
            //1.3 innerWidth()/innerHeight()  
            //方法返回元素 的宽度/高度(包括内边距padding)
//          console.log($('#one').innerWidth());
//          console.log($('#one').innerHeight());
            
            //1.4 outerWidth()/outerHeight    
            //方法返回元素 的宽度/高度(包括内边距padding和边框border)
//          console.log($('#one').outerWidth());
//          console.log($('#one').outerHeight());
            
            //1.5 outerWidth(true)/outerHeight(true)    
            //方法返回元素 的宽度/高度(包括内边距padding和边框border和外边框margin)
//          console.log($('#one').outerWidth(true));
//          console.log($('#one').outerHeight(true));
            
            //1.6 获取页面可视区域的宽高
            console.log($(window).width());
            console.log($(window).height());
        })
    })
</script>

相关文章

  • 17、宽高

    获取宽高的几种方式: css('height') / css('width')获取组件的宽高,带有px,是字符串 ...

  • 2018-04-20

    旧藏~和田玉灵芝耳赏瓶D 尺寸:高17cm,宽8.5cm

  • iOS九宫格布局

    固定——宽高 不固定——宽高

  • 高宽

    box-sizing:content-box;(标准盒子模型,样式宽高即为内容宽高)box-sizing:bord...

  • 图片正则

    去除图片的宽高 匹配宽高 只匹配图片的宽高 直接写样式覆盖

  • 如何获取占位宽(高)、可视区域宽(高)、样式宽(高)

    样式宽(高):就是块级元素自身所带的宽和高; 可视区宽(高):自身所带的宽(高)与左右的内边距的和; 占位宽(高)...

  • jQuery获取宽高

    宽高 width() height() 获取或者设置元素的宽高,这个宽高不包括padding/border/mar...

  • 窗帘尺寸

    主卧,高1.84米,宽2.55米。次卧,高1.73米,宽2.45米。客厅高2.51米,宽3.3米

  • 鱼缸尺寸

    长100高155宽40 长70高120宽40

  • 2021-01-02

    主卧,书房,阳台高2.7宽3 高2.7宽2.7

网友评论

      本文标题:17、宽高

      本文链接:https://www.haomeiwen.com/subject/jtbqwrtx.html