jQuery宽width、高height

jQuery宽width、高height
<div></div>
<div></div>
<div></div>
<div></div>

// 设置jQuery对象列表中,每个元素宽高100像素
$("div").width(100).height("100px");

// 设置jQuery对象列表中,每个元素不同宽度
$("div").width(function(index,item){
    return 50*(index+1);
})
// 设置jQuery对象列表中,每个元素高50像素,设置红色背景色
$("div").height("50px").css("backgroundColor","red");

// 将jQuery列表中第一个元素的宽度返回数值
console.log($("div").width());// number
console.log($("div").css("width"));// string
// 鼠标滑过元素宽度增加
$("div").on("mousemove",function(){
    $(this).width($(this).width()+10)
})

// 获取元素宽度(width+padding)
console.log($("div").innerWidth());
$("div").innerWidth(100);// 和上面相同

// 获取元素宽度(width+padding+border)
console.log($("div").outerWidth());
$("div").outerWidth(100);// 和上面写法相同

//width+padding+border+margin
console.log($("div").outerWidth(true));
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值