首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Webapp -自定义进度条

Webapp -自定义进度条
EN

Stack Overflow用户
提问于 2012-02-09 03:38:12
回答 1查看 292关注 0票数 0

我需要在我的web应用程序中实现一个自定义进度条。我正在使用Smartgwt来构建应用程序UI。进度条应该类似于(但不完全是):

进度条应该是动态的(根据给定的参数,红色和绿色标记)。

应该用什么技术来实现这样一个进度条呢?我应该使用Smartgwt复合扩展吗?使用javascript?

谢谢。

EN

回答 1

Stack Overflow用户

发布于 2012-02-09 05:10:21

您可以使用Javascript和CSS轻松完成此操作。

我将假设以下组件:

代码语言:javascript
复制
bar_container.png (481x36) - this is the empty grey background
bar_content.png (481x36) - this is the colored bar the starts with red and end with green
red_marker.png (20x36)
green_marker.png (20x36)

你需要做的是:

代码语言:javascript
复制
<style>

    .container {
        position: absolute;
        width: 481px;
        height: 36px;
    }

    .content {
        position: absolute;
        left: 0px;
        top: 0px;
        background-image: url(bar_content.png);
        clip:rect(0px, 0px, 36px, 0px); /* modify the second value to adjust width */
    }

    .translucent {
        opacity: 0.5;
    }

    .marker {
        position: absolute;
        left: 0px; /* or where-ever it should be to fit */
        top: 0px;
        width: 20px;
        height: 36px;
    }

    .red {
        background-image: url(red_marker.png);
    }

    .green {
        background-image: url(green_marker.png);
    }

</style>

<div class="container">
    <div class="content">
    </div>
    <div class="marker red">
    </div>
    <div class="content translucent">
    </div>
    <div class="marker green">
    </div>
</div>

<script>

    function setProgressBar(red, green) {  // red and green are values between 0 and 1
        document.querySelector(".content").style.clip = "rect(0px, " + (red * 481) + "px, 36px, 0px)";
        document.querySelector(".translucent").style.clip = "rect(0px, " + (green * 481) + "px, 36px, 0px)";
        document.querySelector(".red").style.left = (red * 481 - 10) + "px";
        document.querySelector(".green").style.left = (green * 481 - 10) + "px";
    }

</script>

您将需要调整这些值。

一个更好的解决方案是将所有这些都封装在一个Javascript函数中,以便可以重用。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9200205

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档