简体   繁体   English

如何制作动画多色进度条?

[英]How To Make an Animated Multi-Color Progress Bar?

I'm rather new so apologies if what I'm asking isn't exactly clear. 我是新来的,所以如果我不清楚的话很抱歉。 I'm trying to build a multi-color progress bar that animates when the page loads. 我正在尝试构建多色进度条,以在页面加载时进行动画处理。 I have found examples similar to what I'm looking for, but the javascript/jquery is what's giving me problems. 我发现了与我正在寻找的示例类似的示例,但是javascript / jquery却给我带来了问题。 I'm not skilled in that area. 我在那方面不熟练。

Example 1: https://codepen.io/tamak/pen/hzEer 示例1: https//codepen.io/tamak/pen/hzEer

That link shows how I want the bar to progressively extend when the page comes up and stop at certain percentages. 该链接显示了我希望页面出现时栏如何逐渐扩展并以一定百分比停止。

jQuery(document).ready(function(){
  jQuery('.skillbar').each(function(){
    jQuery(this).find('.skillbar-bar').animate({
      width:jQuery(this).attr('data-percent')
    },6000);
  });
});

Example 2: http://www.cssflow.com/snippets/animated-progress-bar/demo 示例2: http//www.cssflow.com/snippets/animated-progress-bar/demo

Is very very close to what I'm after, but I want the progress bar to function without the buttons. 非常接近我想要的内容,但是我希望进度条在没有按钮的情况下也能正常运行。 the colors themselves, progressing from red to green, is what I'm trying to achieve. 从红色到绿色的色彩本身就是我想要达到的目标。

Thanks in advance! 提前致谢! I know it's probably asking for a lot, but I'm hoping someone is willing to give it a try. 我知道可能要求很多,但是我希望有人愿意尝试一下。

Maybe this will help: Bootstrap progress bar with gradient color showing proportionally on active width 也许会有所帮助: 渐变颜色的Bootstrap进度条在有效宽度上成比例显示

As for moving the progress bar, how exactly do you want it to change? 至于移动进度条,您到底要如何更改它? You don't need buttons to do it, but something needs to happen. 您不需要按钮即可执行操作,但是需要发生一些事情。 Could you explain that piece in a little more detail? 您能详细解释一下吗?

You can setup click events of buttons with time interval, based on percentage. 您可以根据时间间隔设置按钮的单击事件。

 $(document).ready(function(){ var CurrentProgress = '75%'; setTimeout(function(){ $(".label").each(function() { if($(this).html()==CurrentProgress){ $(this).click(); } }) },1000) }) 
 .container { margin: 80px auto; width: 640px; text-align: center; } .container .progress { margin: 0 auto; width: 400px; } .progress { padding: 4px; background: rgba(0, 0, 0, 0.25); border-radius: 6px; -webkit-box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.25), 0 1px rgba(255, 255, 255, 0.08); box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.25), 0 1px rgba(255, 255, 255, 0.08); } .progress-bar { position: relative; height: 16px; border-radius: 4px; -webkit-transition: 0.4s linear; -moz-transition: 0.4s linear; -o-transition: 0.4s linear; transition: 0.4s linear; -webkit-transition-property: width, background-color; -moz-transition-property: width, background-color; -o-transition-property: width, background-color; transition-property: width, background-color; -webkit-box-shadow: 0 0 1px 1px rgba(0, 0, 0, 0.25), inset 0 1px rgba(255, 255, 255, 0.1); box-shadow: 0 0 1px 1px rgba(0, 0, 0, 0.25), inset 0 1px rgba(255, 255, 255, 0.1); } .progress-bar:before, .progress-bar:after { content: ''; position: absolute; top: 0; left: 0; right: 0; } .progress-bar:before { bottom: 0; background: url("../img/stripes.png") 0 0 repeat; border-radius: 4px 4px 0 0; } .progress-bar:after { z-index: 2; bottom: 45%; border-radius: 4px; background-image: -webkit-linear-gradient(top, rgba(255, 255, 255, 0.3), rgba(255, 255, 255, 0.05)); background-image: -moz-linear-gradient(top, rgba(255, 255, 255, 0.3), rgba(255, 255, 255, 0.05)); background-image: -o-linear-gradient(top, rgba(255, 255, 255, 0.3), rgba(255, 255, 255, 0.05)); background-image: linear-gradient(to bottom, rgba(255, 255, 255, 0.3), rgba(255, 255, 255, 0.05)); } #five:checked ~ .progress > .progress-bar { width: 5%; background-color: #f63a0f; } #twentyfive:checked ~ .progress > .progress-bar { width: 25%; background-color: #f27011; } #fifty:checked ~ .progress > .progress-bar { width: 50%; background-color: #f2b01e; } #seventyfive:checked ~ .progress > .progress-bar { width: 75%; background-color: #f2d31b; } #onehundred:checked ~ .progress > .progress-bar { width: 100%; background-color: #86e01e; } .radio { display: none; } .label { display: none; margin: 0 5px 20px; padding: 3px 8px; color: #aaa; text-shadow: 0 1px black; border-radius: 3px; cursor: pointer; } .radio:checked + .label { color: white; background: rgba(0, 0, 0, 0.25); } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <section class="container"> <input type="radio" class="radio" name="progress" value="five" id="five" checked> <label for="five" class="label">5%</label> <input type="radio" class="radio" name="progress" value="twentyfive" id="twentyfive"> <label for="twentyfive" class="label">25%</label> <input type="radio" class="radio" name="progress" value="fifty" id="fifty"> <label for="fifty" class="label">50%</label> <input type="radio" class="radio" name="progress" value="seventyfive" id="seventyfive"> <label for="seventyfive" class="label">75%</label> <input type="radio" class="radio" name="progress" value="onehundred" id="onehundred"> <label for="onehundred" class="label">100%</label> <div class="progress"> <div class="progress-bar"></div> </div> </section> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM