Javascript事件列表器问题

时间:2015-10-26 11:36:44

标签: javascript css animation

Chrome开发者工具中的控制台显示没有错误,div加载,但动画播放状态仍然暂停 - 我做错了什么?

document.getElementById("design").addEventListener("webkitAnimationEnd", animation);

function animation(){
    "use strict";
    document.getElementById("profile").classList.add("animation");
    location.href = "#profile";
}

CSS

#design {
position: relative;
-webkit-animation: mixdesign;
-webkit-animation-play-state: running;
-webkit-animation-duration: 30s;
-webkit-transition-timing-function: all ease-in-out;
-webkit-animation-iteration-count: 1;
-webkit-animation-fill-mode: forwards;
z-index: 8;
}


/* Profile */

#profile {
position: relative;
-webkit-animation: profile;
-webkit-animation-duration: 30s;
-webkit-animation-play-state: paused;
-webkit-transition-timing-function: all ease-in-out;
-webkit-animation-iteration-count: 1;
-webkit-animation-fill-mode: forwards;
}

.animation { -webkit-animation-play-state: running; }

1 个答案:

答案 0 :(得分:1)

  

正如您在转换结束时分配类一样,现有的类css属性优先于。

     

您可以使用!important关键字覆盖它们。

Fiddle here

document.getElementById("design").addEventListener("webkitAnimationEnd", animation);

function animation() {
  "use strict";
  document.getElementById("profile").classList.add("animation");
}
#design {
  position: relative;
  -webkit-animation: design;
  -webkit-animation-play-state: running;
  -webkit-animation-duration: 3s;
  -webkit-transition-timing-function: all ease-in-out;
  -webkit-animation-iteration-count: 1;
  -webkit-animation-fill-mode: forwards;
  z-index: 8;
}
/* Profile */

#profile {
  position: relative;
  -webkit-animation: profile;
  -webkit-animation-duration: 3s;
  -webkit-animation-play-state: paused;
  -webkit-transition-timing-function: all ease-in-out;
  -webkit-animation-iteration-count: 1;
  -webkit-animation-fill-mode: forwards;
}
.animation {
  -webkit-animation-play-state: running!important;
}
@-webkit-keyframes design {
  10%, 90% {
    -webkit-opacity: 1;
  }
  0%,
  100% {
    -webkit-opacity: 0;
  }
}
/*  Profile: (Animation) */

@-webkit-keyframes profile {
  10%, 90% {
    -webkit-opacity: 1;
  }
  0%,
  100% {
    -webkit-opacity: 0;
  }
}
<div id="design">Design</div>
<div id="profile">profile</div>