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

进度条应该是动态的(根据给定的参数,红色和绿色标记)。
应该用什么技术来实现这样一个进度条呢?我应该使用Smartgwt复合扩展吗?使用javascript?
谢谢。
发布于 2012-02-09 05:10:21
您可以使用Javascript和CSS轻松完成此操作。
我将假设以下组件:
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)你需要做的是:
<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函数中,以便可以重用。
https://stackoverflow.com/questions/9200205
复制相似问题