【问题标题】:jQuery Progress BarsjQuery 进度条
【发布时间】:2012-03-18 18:17:36
【问题描述】:

到底有没有让进度条平滑增加? 我有这个带有按钮的进度条,可以在进度条上加减 10 分(10%) 当然,当按下按钮时,条形“剪辑”到新值,是否有办法让它平滑增加然后剪辑?

编辑:

$(function(){
var progress = $('#progressBar').progressbar({
    value:50
});

$('#upBtn').click(function(){
    progress.progressbar('value', progress.progressbar('value') + 10);        
});

$('#dwnBtn').click(function(){
    progress.progressbar('value', progress.progressbar('value') - 10);        
});

$('button#checkBtn').click(function(){
    var value = progress.progressbar('value');
    if(value > 50 && value < 80){
        $('.incorrect').hide();
        $('.incorrect2').hide();
        $('.correct2').hide();
        $('.balance').hide();
        $('.correct').fadeIn('slow');
    } else if(value < 50 && value > 20){
        $('.correct').hide();
        $('.correct2').hide();
        $('.incorrect2').hide();
        $('.balance').hide();
        $('.incorrect').fadeIn('slow');            
    } else if(value >= 80){
        $('.correct').hide();
        $('.balance').hide();
        $('.incorrect2').hide();
        $('.correct2').fadeIn('slow');            
    } else if(value <= 20){
        $('.correct').hide();
        $('.balance').hide();
        $('.incorrect').hide();
        $('.correct2').hide();
        $('.incorrect2').fadeIn('slow');             
    } else{
        $('.correct').hide();
        $('.incorrect2').hide();
        $('.correct2').hide();
        $('.incorrect').hide();
        $('.balance').fadeIn('slow');    
    }
  });
});

这是基于 Makotosan 给我的代码。我为“检查”按钮添加了 3 个 else if 功能。 如何编辑此代码以使进度条平滑增加。

【问题讨论】:

    标签: jquery progress-bar smooth


    【解决方案1】:

    你可以使用animate()

    //get current width
    var width = $('#yourbarid').width();
    //add 10%
    var newWidth = width*1.1;
    //animate towards newWidth
    $('#yourbarid').animate({ width : newWidth});
    

    【讨论】:

      【解决方案2】:

      如果可以使用 CSS3,请使用 CSS3 动画并使用 jQuery 设置宽度。然后过渡将由浏览器控制动画。

      【讨论】:

      • 嗯.. 你能更好地解释在 CSS3 中使用什么吗?我理解转换,但我必须将它分配给 .ui-progressbar-value 吗?然后呢……
      • 没关系,我找到了。是的,我只需要在 .ui-progressbar-value 上使用一秒钟的 CSS3 过渡,然后游戏就完成了。非常感谢您的建议,我将来可能会更多地使用 CSS3 并深入了解它,看起来很有趣...
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-10
      • 2015-06-19
      • 2011-10-09
      • 2011-12-21
      • 1970-01-01
      相关资源
      最近更新 更多