0

有没有办法可以清理这个 jquery css 更改?像在一个 .css() 上进行所有 css 更改

 $('#container img')
               .css("opacity","1")
               .css("width","339px")
               .css("height", "211px");            
4

3 回答 3

6

我会添加一个 CSS 类。

$('#container img').addClass("foo");

在哪里

.foo{
   opacity: 1;
   width: 399px;
   height: 211px;
}

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

于 2013-08-27T19:02:21.170 回答
2

这应该有效:

$('#container img').css({
  opacity: 1,
  width: "339px",
  height: "211px"
});
于 2013-08-27T19:03:44.053 回答
1

http://api.jquery.com/css/#css-properties

$('#container img').css({opacity: 1, width: "339px", height: "211px" })
于 2013-08-27T19:03:24.127 回答