[英]how to detect percent width in css file with jquery
我想用jQuery从CSS文件中获取宽度,但是当使用这种方法时:
$('element').width()
或 $('element').css('width');
获取像素大小元素,但在css文件中此元素具有百分比大小....
如何获得它。 html:
<div id="content"></div>
的CSS
#content{width:50%}
为了无聊:
var mywidth = $('#content').width(),
parentwidth = $('#content').parent().width(),
percentagewidth = (mywidth*100)/parentwidth;
alert(precentagewidth+"%");
==四舍五入==
Math.round(precentagewidth)
Math.round()文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.