[英]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.