清理jquery css更改试图使它成为一行

Wan*_*arn 0 jquery

有没有办法可以清理这个jquery css的变化?像所有css更改的东西都在一个.css()

 $('#container img')
               .css("opacity","1")
               .css("width","339px")
               .css("height", "211px");            
Run Code Online (Sandbox Code Playgroud)

quo*_*uoo 6

我会添加一个CSS类.

$('#container img').addClass("foo");
Run Code Online (Sandbox Code Playgroud)

哪里

.foo{
   opacity: 1;
   width: 399px;
   height: 211px;
}
Run Code Online (Sandbox Code Playgroud)

这种技术称为有状态CSS,对于操作UI非常有用:http://timgthomas.com/2012/05/mute-your-asynchronous-uis-with-stateful-css/