如何在Javascript中更改关键帧状态

时间:2016-03-25 20:19:56

标签: javascript jquery css keyframe

我想用JQuery动态更改关键帧状态 这是我的关键帧:

@keyframes moveItUp {
    10% {
        top: 18%;
    }
    20% {
        top: 16%;
    }
    30% {
        top: 14%;
    }
    40% {
        top: 12%;
    }
    50% {
        top: 10%;
    }
    60% {
        top: 8%;
    }
    70% {
        top: 6%;
    }
    80% {
        top: 4%;
    }
    90% {
        top: 2%;
    }
    100% {
        top: -20px;
    }
}

例如,我想用Javascript

从20%切换到40%等动态

我该怎么做?感谢

1 个答案:

答案 0 :(得分:1)

a great blog article on MSDN解释了如何做到这一点。

  var rule;    
  var ss = document.styleSheets;

  for (var i = 0; i < ss.length; ++i) {

      // loop through all the rules!
      for (var x = 0; x < ss[i].cssRules.length; ++x) {

          rule = ss[i].cssRules[x];
          if (rule.name == "moveItUp" && rule.type == CSSRule.KEYFRAMES_RULE) {

              // do what you need to do here
          }
      }
  }