
我没有找到js获取元素宽度包含小数点的方法,但是在使用获取到的宽度时,为了保证与原来元素的宽度一致,我在工作中的解决方案是:
var oldw=$(oldElement)width();
$(newElement)css("width",oldw+"px");
$(oldElement)css("width",oldw+"px');
刚看到有getComputedStyle这个方法,还有这个getClientBoundingRect()。可以。
function sunWidth(){
var w1 = 0;
var $lis = $(this)children("ul")children("li")
$liseach(function(){
w1 += thisouterwidth(/true/);//参数true表示包括边距(margin);
});
return w1;
}
alert (sunWidth())
使用过程中需要主要获取的高度范围包含 盒子模型中的哪些元素、
height() : 其高度范围是所匹配元素的高度 height;(content 的高度)
innerHeight() : 其高度范围是所匹配元素的高度 height + padding ;
outerHeight() : 其高度范围是所匹配元素的高度height + padding + border ;
outerHeight(true) : 其高度范围是所匹配元素的高度 height + padding + border + margin ;
同理宽度有: width() | innerWidth() | outerWidth() | outerWidth(true)
在线demo》》》>
html代码----
<div class="div1">123
</div>
<div class="div2">
456
</div>
<div class="div2">
789
</div>
js代码----
$(document)ready(function() {//第二个div2偏移
$("div2")eq(1)css("margin-left", $("div1")width());
});
css代码--------
div1 {background: blue;
float: left;
}
div2 {
background: green;;
clear: both;
float: left;
}
jQuery 的 index() 方法返回指定元素相对于其他指定元素的索引值,注意:索引值是从0开始计数的。获得当前元素的索引值可用click事件触发 $(selector)click(function() { num = $(this)index();}示例代码如下:获取被点击的a标签的索引值 创建
以上就是关于大神,jquery或者js 怎么获取到元素宽度包含小数点全部的内容,包括:大神,jquery或者js 怎么获取到元素宽度包含小数点、大神,请问jquery怎么获取ul下的多个li元素的宽度总和、jQuery 获取容器宽度和长度等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)