2012-03-21 81 views
1

有没有办法让一个CSS函数动态?是否可以更改CSS动画宽度javascript?

.test2 
{ 
    width:200px; 
    height: 90%; 
    -webkit-animation:myfirst2 linear; /* Safari and Chrome */ 
    -webkit-animation-duration: 10s; 
} 

@-webkit-keyframes myfirst2 /* Safari and Chrome */ 
{ 
    from { height: 0%; } <--this must be dynamic 
    to { height: 90%; } <--this must be dynamic 
}  

我想from { height: 0%; }to { height: 90%; }动态使用JavaScript。

这可能吗?

+0

你可以做到这一点btw – tkone 2012-03-21 11:34:54

+1

这看起来是你想要的:http://stackoverflow.com/questions/2495829/dynamically-modify-webkit-animation-with-javascript – callumacrae 2012-03-21 11:36:03

+0

是的,谢谢Callum Macrae。这是我正在寻找的解决方案。 – robind38 2012-03-21 12:43:14

回答

5

您可以使用jQuery的CSS()函数

$('.foo').css({'-webkit-animation': 'myfirst2 linear', '-webkit-animation-duration': '10s'}); 
0

可以伊斯利让步的.css

这样的

//Fade in Background 
      jQuery('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeOut(); //Fade in the fade layer  


     //Apply Margin to Popup 
      jQuery('#' + popID).css({ 
       'margin-top' : -popMargTop, 
       'margin-left' : -popMargLeft, 
       'display' : 'block' 
      });