Jquery提供了一系列的方法让程序员去设置CSS的属性.
把它们都总结如下:
css()
sample:
1. $("p").css("color","red"); //设置元素的颜色
2. $("p").css("color"); //返回第一个匹配的样式属性值
3. $("p").css({"color":"red", "background-color":"black"});
注:该方法不支持简写的Css属性(如 background or border)
height()
sample:
1. $("p").height(50);//设置所有P元素的高度
2. $("p").height();//返回第一个匹配的元素的高度
$(window).height();
$(document).height();
lenght()
sample:
1. $("p").width(50);//设置所有P元素的宽度
2.$
("p").width();//返回第一个匹配的元素的宽度
注:可以用em 和 %来者是宽度
offset()
sample
1. var x = $("p").offset();
x.left;
x.top;
2. $("p").offset({top:100,left:0});
3. $("P").offset($("span").offset());
注:是相对于文档的偏移位置
offsetParent()
sample
$("p").offsetParent().css("background-color","red");
注:返回最近的祖先定位元素,定位元素指position: relative/absolute/fixed 的元素
position()
sample
$("p").position();
注:返回匹配元素相对于父元素的位置(偏移),包括top, left
scrollLeft() scrollTop()
sample
$("div").scrollLeft(100);
注:方法返回或设置匹配元素的滚动条的水平位置
当用于获取值时,该方法只返回第一个匹配元素的 scroll left offset。
当用于设置值时,该方法设置所有匹配元素的 scroll left offset。