我试图呈现像在图像输出如何使用数组的最大值设置宽度?
现在,我想所有的数字值传递到一个数组,然后设置灰色条的长度,以该最大的价值 这是我迄今为止,但它不传递任何值:
var contentValues = $('facet-amount').text();
var arr = parseInt(contentValues);
$(".facet-percentage").width(Math.max(...arr));
.facet {
position: relative;
border: 1px solid #dcdcdc;
margin-top: 13px;
}
.facet-title {
display: inline-block;
}
.facet-amount {
display: inline-block;
position: absolute;
right: 2px;
}
.facet-percentage {
background-image: -webkit-linear-gradient(top, #f8f8f8, #e5e5e5);
display: inline-block;
height: 10%;
position: absolute;
z-index: -1;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="content-type-facet" class="facet">
<div class="facet-header">
<h3>Content Type</h3>
</div>
<div>
<span class="facet-percentage" style=""></span>
<span class="facet-title">Chapter</span>
<span class="facet-amount">400</span>
</div>
<div>
<span class="facet-percentage" style=""></span>
<span class="facet-title">Article</span>
<span class="facet-amount">200</span>
</div>
<div>
<span class="facet-percentage" style=""></span>
<span class="facet-title">Reference Work Entry</span>
<span class="facet-amount" id='ciao'>207</span>
</div>
<div>
<span class="facet-percentage" style=""></span>
<span class="facet-title">Protocol</span>
<span class="facet-amount">16</span>
</div>
<div>
<span class="facet-percentage" style=""></span>
<span class="facet-title">Book</span>
<span class="facet-amount">2</span>
</div>
</div>
.facet量,以点...和执行console.log(ARR)然后... – sinisake
因此,所有的'.facet,percentage'应该是400px? –