有没有办法可以清理这个 jquery css 更改?像在一个 .css() 上进行所有 css 更改
$('#container img')
.css("opacity","1")
.css("width","339px")
.css("height", "211px");
有没有办法可以清理这个 jquery css 更改?像在一个 .css() 上进行所有 css 更改
$('#container img')
.css("opacity","1")
.css("width","339px")
.css("height", "211px");
我会添加一个 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/
这应该有效:
$('#container img').css({
opacity: 1,
width: "339px",
height: "211px"
});
http://api.jquery.com/css/#css-properties
$('#container img').css({opacity: 1, width: "339px", height: "211px" })