【问题标题】:Why does my progress bar shows full progress value before it start loading为什么我的进度条在开始加载之前显示完整的进度值
【发布时间】:2014-02-05 04:47:00
【问题描述】:

我使用 jQuery UI 制作了一个进度条。这是查看它的链接:DEMO

效果很好,就是有问题。在代码中我有setTimeout( progress, 2000 );,这意味着它必须等待 2 秒才能启动。但在此期间,它显示 .ui-progressbar-value 的背景,当整个进度完成时必须可见。 2 秒后它会像往常一样隐藏并进步星星。

有趣的是,当我在 JSFiddle 上尝试它时,它没有显示这个类并且运行良好。所以在浏览器中只有这个问题。 Here is the JSFiddel link

这是我的 js 代码:

$(function() {
    var progressbar = $( "#progressbar" ),
      progressLabel = $( ".progress-label" );

    progressbar.progressbar({
      value: false,
      change: function() {
        progressLabel.text( progressbar.progressbar( "value" ) + "%" );
      },
      complete: function() {
        progressLabel.text( "100%" );
        $(".loader").delay(1000).fadeOut(750);
      }
    });

    function progress() {
      var val = progressbar.progressbar( "value" ) || 0;

      progressbar.progressbar( "value", val + 1 );

      if ( val < 100 ) {
        setTimeout( progress, 100 );
      }

    }

    setTimeout( progress, 2000 );
  });

还有 CSS:

.enterance{
    position:absolute;
    overflow:hidden;
    left:0;
    top:0;
    background-color:black;
    width:100%; 
    height:100%;
    z-index:10;
    color:rgba(255,255,255,1.00);
}
.enterance .loader{
    position:absolute;
    width:600px;
    height:500px;
    top:50%;
    left:50%;
    margin:-250px 0 0 -300px;
}
.ui-progressbar-value {
    background:url(http://goo.gl/V9dAfn) no-repeat;
    width:600px;
    height:429px;
    border:0;
}
.ui-progressbar{
    background:url(http://goo.gl/rBH0N1) no-repeat;
    background-size:cover;
    width:600px;
    height:429px;
    border:0;
}
.ui-progressbar .ui-progressbar-value{margin:0;}
.progress-label{
    font-size:90px;
    font-family: 'News Cycle', sans-serif;
    color:#FFFFFF; 
    right:0px; 
    position:absolute;
}

那么我怎么能在它等待 2 秒时不显示这个 .ui-progressbar-value?此外,我怎样才能为此添加淡入淡出效果?就像页面加载时图像淡入一样?

提前致谢。

【问题讨论】:

  • @bits e 稍后会有一些内容,我们为什么要为此烦恼。顺便说一句,加载器也不错:)
  • @bits 这不是整个项目。对于我正在开发的网站,它确实需要一个假加载器。但是,问题是我在主要问题中描述的。你有什么想法来解决这个问题吗? :)

标签: javascript jquery html css progress-bar


【解决方案1】:

试试这个(除非你有问题,否则无法确定):

$(function() {
    var progressbar = $( "#progressbar" ),
      progressLabel = $( ".progress-label" );

    progressbar.progressbar({
      value: false,
      change: function() {
        progressLabel.text( progressbar.progressbar( "value" ) + "%" );
      },
      complete: function() {
        progressLabel.text( "100%" );
        $(".loader").delay(1000).fadeOut(750);
      }
    });

    function progress() {
      var val = progressbar.progressbar( "value" ) || 0;

      progressbar.progressbar( "value", val + 1 );

      if ( val < 100 ) {
        setTimeout( progress, 100 );
      }
    }

    progressbar.progressbar( "value", 0 );
    setTimeout( progress, 2000 );
  });

【讨论】:

  • 感谢您的帮助。页面一加载就开始加载。但它必须等待几秒钟才能启动。
  • 同样的事情。进度一加载就开始了。 ://
  • 抱歉,我忘了恢复之前的更改。立即尝试。
  • Awww,我只是在你的答案中改变了一些东西,它起作用了。我删除了progress(); 并添加了setTimeout( progress, 2000 );,它现在可以工作了。
  • 我所做的只是在 css 中为 .enterance .loader 添加 display:none; 并在第一个 setTimeout 之前添加 $(".loader").delay(1000).fadeIn(750);
【解决方案2】:

尝试删除“$(function()”并只运行纯代码?

var progressbar = $( "#progressbar" ),
      progressLabel = $( ".progress-label" );

    progressbar.progressbar({
      value: false,
      change: function() {
        progressLabel.text( progressbar.progressbar( "value" ) + "%" );
      },
      complete: function() {
        progressLabel.text( "100%" );
        $(".loader").delay(1000).fadeOut(750);
      }
    });

    function progress() {
      var val = progressbar.progressbar( "value" ) || 0;

      progressbar.progressbar( "value", val + 1 );

      if ( val < 100 ) {
        setTimeout( progress, 100 );
      }

    }

    setTimeout( progress, 2000 );

因为它不影响小提琴,所以真的不能用它吗?

【讨论】:

  • 感谢您的帮助。我刚试过,但没有用。 :(
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-11-01
  • 2021-05-07
  • 1970-01-01
  • 2015-08-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多