js增加样式表

var rule=`@-webkit-keyframes run${ this.index }{
              0% {
                transform:translateX(500px);
               } 
               100%{
                 transform:translateX(-${ w }px));
              }
             };
        var stylesheet = document.styleSheets[document.styleSheets.length-1];
        console.log(stylesheet)
        try {
            stylesheet.insertRule( rule , stylesheet.rules.length);
        } 
       catch (e) {
         console.log(this.index);
      };
    this.showdata[this.index].animation='run'+ this.index +' 8s linear forwards';

你可能感兴趣的:(js增加样式表)