javascript - 使用javascript的男性女性百分比分布动态图像

标签 javascript css

Percentage distribution

我在这里使用女性和男性的图像作为 Logo ,我正在通过 javascript 计算百分比,但图像是静态的,我想将其转换为动态。

意味着假设这里女性的百分比是 55%,那么在图像中我们将 Logo 视为一半填充和一半空白。但如果我们得到的结果百分比为女性 10%,那么我的 Logo 看起来也与图像中所示的相同。因为它是静态图像。我想让它动态化。 我是 css、javascript 的新手。 任何起点或引用链接也会对我有帮助。 提前致谢。

最佳答案

您可以尝试这个概念:

HTML:

<span class="percentage"><span style="height:45%;"></span></span>

CSS:

.percentage {
    width:41px;
    height:97px;
    display:inline-block;
    position:relative;
    background:url(gray.png) no-repeat left bottom;
}
.percentage span {
    width:100%;
    height:0;
    display:inline-block;
    position:absolute;
    left:0; bottom:0;
    background:url(blue.png) no-repeat left bottom;
}

图片:

enter image description here enter image description here

Demo Link:

关于javascript - 使用javascript的男性女性百分比分布动态图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32776199/

相关文章:

javascript - 在 Javascript 上拖放

javascript - 如何从下拉菜单中获取值

javascript - fancybox 中的两个标题?

javascript - 我想停止提交整个页面并使用 javascript 仅提交我的表单

CSS 媒体查询 - 逐渐调整大小?

css - 有没有办法在禁用时从 Angular 垫形式字段中删除边框?

javascript - Vue.js 组件彼此不独立

javascript - Prime Factors 函数使控制台崩溃

html - 在显示器内使用相对位置 :table-cell in Firefox. 包装器解决方案防止垂直对齐:中间

html - 用 iFrame 填充窗口而不显示滚动条?