Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/437.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何根据贡献百分比计算排名前三的贡献者领奖台高度?_Javascript_Jquery_Html_Css_Math - Fatal编程技术网

Javascript 如何根据贡献百分比计算排名前三的贡献者领奖台高度?

Javascript 如何根据贡献百分比计算排名前三的贡献者领奖台高度?,javascript,jquery,html,css,math,Javascript,Jquery,Html,Css,Math,考虑以下顶级论坛贡献者讲台: 正如你所见,看台的高度是恒定的。我想根据贡献百分比来设定高度,这样,如果第一和第二名分别为25.6%和25.8%,那么相应的展位高度将几乎相同 如何根据贡献百分比计算高度?在传递给高度函数的值中,需要使用“%”传递高度百分比 将“计算高度”功能更改为如下所示 试试这个: $(function() { var first = 42.3; var second = 34.2; var third = 10.7; var heights =

考虑以下顶级论坛贡献者讲台:

正如你所见,看台的高度是恒定的。我想根据贡献百分比来设定高度,这样,如果第一和第二名分别为25.6%和25.8%,那么相应的展位高度将几乎相同


如何根据贡献百分比计算高度?

在传递给高度函数的值中,需要使用“%”传递高度百分比

将“计算高度”功能更改为如下所示

试试这个:

$(function() {
    var first = 42.3;
    var second = 34.2;
    var third = 10.7;
    var heights = calc_heights(first, second, third);

    $(".first").height(heights[0] + "%").html(first);
    $(".second").height(heights[1] + "%").html(second);
    $(".third").height(heights[2] + "%").html(third);
});

function calc_heights(first, second, third) {
    var total = (first+second+third)/100;
    return [first/total, second/total, third/total];
}

我想我不明白这个问题。