您的位置:首页 > Web前端 > JQuery

jquery学习手记(6)CSS, Styling, & Dimensions

2013-04-18 22:19 274 查看

Css方法

// Getting CSS properties
$("h1").css("fontSize"); // returns a string such as "19px"
$("h1").css("font-size"); // also works

// Setting CSS properties
$("h1").css( "fontSize", "100px" ); // setting an individual property

// setting multiple properties
$("h1").css({
fontSize: "100px",
color: "red"
});


Styling方法

// Working with classes
var $h1 = $("h1");
$h1.addClass("big");
$h1.removeClass("big");
$h1.toggleClass("big");
if ( $h1.hasClass("big") ) { ... }


Dimensions

// Basic dimensions methods
// sets the width of all H1 elements
$("h1").width("50px");
// gets the width of the first H1
$("h1").width();
// sets the height of all H1 elements
$("h1").height("50px");
// gets the height of the first H1
$("h1").height();
// returns an object containing position
// information for the first H1 relative to
// its "offset (positioned) parent"
$("h1").position();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: