Ich versuche, den Text jedes .totalInput
innerhalb jedes .subgroup
zu reskalieren und es in das width
Attribut zu übergehen, wie kann ich es tun?Wie skaliert man einen Wert innerhalb jeder Teilmenge von Elementen?
$('div.subgroup').each(function(index, element) {
var maxLength = Math.max.apply(Math, $(".totalInput", this).map(function() {
return $(this).text();
}).get());
$('.totalInput').each(function(index, element) {
var tot = element;
$(element).siblings(".facet-percentage").width(parseInt(($(element).text()/maxLength)) + '%');
});
});
span {display:inline-block}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class='group'>
<div class='subgroup'>
<span class='facet-percentage' width=''></span>
<span class='totalInput'>10</span>
<span class='facet-percentage' width=''></span>
<span class='totalInput'>20</span>
<span class='facet-percentage' width=''></span>
<span class='totalInput'>30</span>
</div>
<div class='subgroup'>
<span class='facet-percentage' width=''></span>
<span class='totalInput'>50</span>
<span class='facet-percentage' width=''></span>
<span class='totalInput'>100</span>
<span class='facet-percentage' width=''></span>
<span class='totalInput'>70</span>
</div>
</div>
Derart, dass die Ausgabe der ersten Untergruppe würde:
<div class='subgroup'>
<span class='facet-percentage' width='33%'></span>
<span class='totalInput'>10</span>
<span class='facet-percentage' width='66%'></span>
<span class='totalInput'>20</span>
<span class='facet-percentage' width='100%'></span>
<span class='totalInput'>30</span>
</div>
Möchten Sie das Attribut width jedes '.facet-Prozentsatzes 'auf den Wert des ersten' .totalInput' setzen, der danach kommt? –
Wenn Sie von der Breite abhängig sind, stellen Sie sicher, dass Sie 'span {display: inline-block}}' – zer00ne
haben Es sollte das Maximum der Menge der 3 von ihnen nehmen und jeden Wert neu skalieren. So wäre zum Beispiel der erste Satz "10/30", "20/30", "30/30" und wird in Prozent neu skaliert. – Dambo