window.location麻烦的jQuery代码

高朗·丹顿(Gaurang Tandon)

我正在尝试构建一个进度条,该进度条在延迟0.1秒后完成,用剪辑效果隐藏该条,然后在延迟0.2秒后再次加载该页面,以加载google.com。

我的代码:

<!doctype html>

<html lang="en">
<head>
  <meta charset="utf-8" />
  <title>jQuery UI Progressbar - Custom Label</title>
  <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
  <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
  <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
  <link rel="stylesheet" href="/resources/demos/style.css" />
  <style>
  .ui-progressbar {
    position: relative;
  }
  .progress-label {
    position: absolute;
    left: 50%;
    top: 4px;
    font-weight: bold;
    text-shadow: 1px 1px 0 #fff;
  }
  </style>
  <script>
  $(function() {
    var progressbar = $( "#progressbar" ),
      progressLabel = $( ".progress-label" );

    progressbar.progressbar({
      value: false,
      change: function() {
        progressLabel.text( progressbar.progressbar( "value" ) + "%" );
      },
      complete: function() {
        progressLabel.text( "Complete!" );
        $( "#progressbar" ).delay(100).hide("clip").delay(200);
        window.location = "http://www.google.com";
      }
    });

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

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

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

    }

    setTimeout( progress, 3000 );

  });
  </script>
</head>
<body>

<div id="progressbar"><div class="progress-label">Loading...</div></div>


</body>
</html>

问题在于,即使尚未发生效果,该页面也会加载http://www.google.com我可以使用某种时间延迟吗?

谢谢。

苏雷什·阿塔(Suresh Atta)

尝试一下 setTimeout

complete: function() {
        progressLabel.text( "Complete!" );
        $( "#progressbar" ).delay(100).hide("clip").delay(200);
       setTimeout(function() {

       window.location.href = "http://www.google.com" 

         }, 2000);
      }

这样它等待2秒。

了解有关SetTimeOut的更多信息

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章