有沒有辦法我可以清理這個jQuery的css更改?像所有的CSS變化是在一個.css()清理jQuery的css更改試圖使其一條線
$('#container img')
.css("opacity","1")
.css("width","339px")
.css("height", "211px");
有沒有辦法我可以清理這個jQuery的css更改?像所有的CSS變化是在一個.css()清理jQuery的css更改試圖使其一條線
$('#container img')
.css("opacity","1")
.css("width","339px")
.css("height", "211px");
這應該工作:
$('#container img').css({
opacity: 1,
width: "339px",
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/
是的,添加一個類並使用CSS。 – peterchon
http://api.jquery.com/css/#css-properties
$('#container img').css({opacity: 1, width: "339px", height: "211px" })
難道你不能把它變成一個班級嗎? – Sergio