【问题标题】:I got a HTML & CSS progress bar. what i need now is that it should load a page on complete. any ways?我有一个 HTML & CSS 进度条。我现在需要的是它应该加载一个完整的页面。无论如何?
【发布时间】:2015-03-26 09:57:04
【问题描述】:

//这是我的 HTML 我在这里需要的是,在进度条完全加载时,它应该重定向到另一个页面。 有什么办法吗?!!!!

.text-center {
    text-align: center;
}

.container {
    left: 50%;
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%);
}

.progress {
    background-color: #e5e9eb;
    height: 0.25em;
    position: relative;
    width: 24em;
}
.progress-bar {
    -webkit-animation-duration: 3s;
    -webkit-animation-name: width;
    background: linear-gradient(to right, #4cd964, #5ac8fa, #007aff, #34aadc, #5856d6, #ff2d55);
    background-size: 24em 0.25em;
    height: 100%;
    position: relative;
}
.progress-shadow {
    background-image: linear-gradient(to bottom, #eaecee, transparent);
    height: 4em;
    position: absolute;
    top: 100%;
    transform: skew(45deg);
    transform-origin: 0 0;
    width: 100%;
}

/* ANIMATIONS */
@keyframes width {
       0%, 100% {
       transition-timing-function: cubic-bezier(1, 0, 0.65, 0.85);
  }
  0% {
       width: 0;
  }
   100% {
      width: 100%;
  }
}
@-webkit-keyframes width {
       0%, 100% {
       transition-timing-function: cubic-bezier(1, 0, 0.65, 0.85);
  }
  0% {
       width: 0;
  }
   100% {
      width: 100%;
  }
}
  <div class="container">
  <h2 class="text-center">Loading</h2>
  <div class="progress">
    <div class="progress-bar">
      <div class="progress-shadow"></div>
      </div>
  </div>
</div>

帮帮我!! 而且我这里没有任何java脚本。 如果我能在没有 java 脚本的情况下做到这一点,我会更高兴。 所以请帮帮我。

更新 发现java脚本动画结束可能会有所帮助。

【问题讨论】:

标签: html css onload progress


【解决方案1】:

只需使用this trick highlighted by David Walsh。他为transitionend 做的,但我们可以把它换成animationend

他的诀窍是遍历所有供应商前缀和本机animationend 事件的列表,并检查浏览器是否支持其中任何一个。然后,他将已识别的 animationend 处理程序附加到感兴趣的元素。

当动画结束事件被触发时,我们只需使用window.location.replace()as mentioned before 重定向到感兴趣的 URL。

我已对其进行了修改,使其适用于您的场景:

$(function() {

    // Check with animationend event is supported by browser
    function whichAnimationEvent(){
        var t;
        var el = document.createElement('fakeelement');
        var animations = {
          'animation':'animationend',
          'OAnimation':'oAnimationEnd',
          'MozAnimation':'animationend',
          'WebkitAnimation':'webkitAnimationEnd'
        }

        for(t in animations){
            if( el.style[t] !== undefined ){
                return animations[t];
            }
        }
    }

    // Listen for animation
    var animationEvent = whichAnimationEvent(),
        progress = document.getElementsByClassName('progress-bar')[0];

    animationEvent && progress.addEventListener(animationEvent, function() {
        // Alert (to demonstrate the code works)
        alert('Animation complete!  This is the callback, no library needed!');

        // Redirect script
        window.location.replace('/path/to/url');
    });
});

请看这里的小提琴:http://jsfiddle.net/teddyrised/9w7pntmt/3/

【讨论】:

  • 它在 jsfiddle 中完美运行。但不在我的服务器上,请按 JS 提示并查看错误。
  • @AlokRajasukumaran 您的浏览器控制台中有哪些错误消息?如果它在小提琴中工作,只要加载了 jQuery,它就应该在其他地方工作。 window.location.replace 仅适用于同源请求。和closing ; are optional in JS when there is a linebreak。这与代码是否工作无关,仅出于一致性原因。
  • 可能的问题是js没有加载到我的html中。我都很困惑它应该在哪里加载。给了身体负载,在身体负载之后它仍然不起作用。 :(
  • 把它包裹在$(function() { ... });DOM ready handler中。由于 JS 只会在 DOM 就绪时进行评估,因此您可以将其放置在任何位置,但 jQuery. 之后
  • ., 能否请您提供完整的新代码集。作为 js 的新手,我对此感到困惑。 :P
【解决方案2】:

好的,我完全找到了解决方案。 如果有人对此有任何问题,请报告。

function whichAnimationEvent() {
  var t;
  var el = document.createElement('fakeelement');
  var animations = {
    'animation': 'animationend',
    'OAnimation': 'oAnimationEnd',
    'MozAnimation': 'animationend',
    'WebkitAnimation': 'webkitAnimationEnd'
  };

  for (t in animations) {
    if (el.style[t] !== undefined) {
      return animations[t];
    }
  }
}

function oload() {
    var animationEvent = whichAnimationEvent(),
      progress = document.getElementsByClassName('progress-bar')[0];

    animationEvent && progress.addEventListener(animationEvent, function() {
      window.location.replace("http://alokraj68.in");
    });
  }
  // Listen for animation
html,
body {
  height: 100%;
}
body {
  background-color: #f5f7f9;
  color: #6c6c6c;
  font: 300 1em/1.5em"Helvetica Neue", sans-serif;
  margin: 0;
  position: relative;
}
h1 {
  font-size: 2.25em;
  font-weight: 100;
  line-height: 1.2em;
  margin: 0 0 1.5em;
}
.text-center {
  text-align: center;
}
.container {
  left: 50%;
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
}
.progress {
  background-color: #e5e9eb;
  height: 0.25em;
  position: relative;
  width: 24em;
}
.progress-bar {
  -webkit-animation-duration: 3s;
  -webkit-animation-name: width;
  background: linear-gradient(to right, #4cd964, #5ac8fa, #007aff, #34aadc, #5856d6, #ff2d55);
  background-size: 24em 0.25em;
  height: 100%;
  position: relative;
}
.progress-shadow {
  background-image: linear-gradient(to bottom, #eaecee, transparent);
  height: 4em;
  position: absolute;
  top: 100%;
  transform: skew(45deg);
  transform-origin: 0 0;
  width: 100%;
}
/* ANIMATIONS */

@keyframes width {
  0%, 100% {
    transition-timing-function: cubic-bezier(1, 0, 0.65, 0.85);
  }
  0% {
    width: 0;
  }
  100% {
    width: 100%;
  }
}
@-webkit-keyframes width {
  0%, 100% {
    transition-timing-function: cubic-bezier(1, 0, 0.65, 0.85);
  }
  0% {
    width: 0;
  }
  100% {
    width: 100%;
  }
}
<html>

<head>
  <meta charset="UTF-8">
  <title>alokraj68.in--Loading!!</title>
  <link rel="stylesheet" href="css/loading.css">
  <script src="js/script.js"></script>
</head>

<body onload="oload()">
  <div class="container">
    <h1 class="text-center">alokraj68.in</h1>
    <h2 class="text-center">Loading</h2>
    <div class="progress">
      <div id="pb" class="progress-bar">
        <div class="progress-shadow"></div>
      </div>
    </div>
  </div>
</body>

</html>

试试这个编码。 如果有人发现任何问题,请告诉我。

【讨论】:

    猜你喜欢
    • 2011-06-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-23
    • 1970-01-01
    • 2023-03-20
    • 1970-01-01
    • 2017-05-24
    相关资源
    最近更新 更多