JS——jquery宽高的设置

127 篇文章 2 订阅
111 篇文章 1 订阅

描述:

jquery宽高的设置

实现:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        div
        {
            width: 100px;
            height: 100px;
            background-color: deepskyblue;
            border: 2px solid #000000;
            padding: 10px;
            margin: 20px;

        }

        .div1
        {
            margin: 0;
            padding: 0;
            border: none;
            position: relative;
            left:50px;
            top:50px;
        }
        .div2
        {
            width: 50px;
            height: 50px;
            background-color: crimson;
            margin: 0;
            padding: 0;
            border: none;
            position: absolute;
            left:20px;
            top:20px
        }
    </style>
    <script src="node_modules/jquery/dist/jquery.js"></script>
</head>
<body>
    <div></div>
    <div></div>
    <div></div>
    <div class="div1">
        <div class="div2"></div>
    </div>

    <script>
//       $("div").width(100).height("100px");
//        console.log($("div").width());//获取宽度
        
        /*$("div").width(function (index) {
            return (index+1)*50
        })*/

        /*$("div").width(50)
            .height(50)
            .css("backgroundColor","red")*/


//        console.log($("div").innerWidth());//width+padding
//        $("div").innerWidth(100);//设置的值会减去padding值然后赋值给width


//        console.log($("div").outerWidth());//width+padding+border
//        $("div").outerWidth(100);//值-padding-border,然后赋值给width

//        console.log($("div").outerWidth(true));//width+padding+border+margin
//  只能获取
//        var rect=div.getBoundingClientRect();
//      获取相对页面的绝对定位
//        console.log($(".div2").offset());//getBoundingClientRect()一样
//        $(".div2").offset({left:0,top:0});//可以设置,必须写对象,而且必须是left和top


//        console.log($(".div2").position());//相对父容器定位位置
//        $(".div2").position({left:0,top:0});//错误的,不可以设置的

//        console.log($(".div2").position().left);//div2.offsetLeft
//        console.log($(document).scrollTop());//获取当前滚动条的位置
//        $(document).scrollTop(100);// 设置滚动条位置
    </script>
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值