日期:2014-05-17  浏览次数:20507 次

(七)jquery总结:CSS

JQuery CSS 方法说明

css( name ) 访问第一个匹配元素的样式属性。
css( properties ) 把一个”名/值对”对象设置为所有匹配元素的样式属性。
$(”p”).hover(function () {
$(this).css({ backgroundColor:”yellow”, fontWeight:”bolder” });
}, function () {
var cssObj = {
backgroundColor: “#ddd”,
fontWeight: “”,
color: “rgb(0,40,244)”
}
$(this).css(cssObj);
});
css( name, value ) 在所有匹配的元素中,设置一个样式属性的值。
offset( ) 取得匹配的第一个元素相对于当前可视窗口的位置。返回的对象有2个属性,
top和left,属性值为整数。这个函数只能用于可见元素。
var p = $(”p:last”);
var offset = p.offset();
p.html( “left: ” + offset.left + “, top: ” + offset.top );
width( ) 取得当前第一匹配的元素的宽度值,
width( val ) 为每个匹配的元素设置指定的宽度值。
height( ) 取得当前第一匹配的元素的高度值,
height( val ) 为每个匹配的元素设置指定的高度值。