JQuery中css的操作

2021-10-18 19:29:43 字數 1778 閱讀 4087

設定屬性三種方式:

css(name)								//獲取屬性值

css(name,value)

css()

css( name,function( index,value ) ) //索引,原先的屬性值

'box'

>

111<

/div>

$(function()

)//()$(

'#box').

css(

'textalign'

,function

(index, value)

)//( name,function( index,value ) )

console.

log($(

'#box').

css(

'color'))

;})<

/script>

//元素寬高

console.

log($(

'#box').

width()

);console.

log($(

'#box').

height()

);//元素內容寬高 內間距+內容區域 (不包含邊框)

console.

log($(

'#box').

innerwidth()

);console.

log($(

'#box').

innerheight()

);//包含元素的 內間距+內容區域+邊框

//boolean引數 true false 是否計算邊距

console.

log($(

'#box').

outerwidth

(true))

; console.

log($(

'#box').

outerheight()

);

3.1 offset(元素預設相對定位)

獲取元素偏移量offset()

設定元素偏移量offset()

='box'

>

'box'

>

<

/div>

<

/div>

$(function()

) console.

log($(

'#box').

offset()

);})

<

/script>

3.2 position(元素相對于父元素定位)

console.

log($(

'#box').

position()

);

3.3 scroll(設定元素的滑動距離)

$

('#box').

scrolltop()

$('#box').

scrollleft

()

jQuery中的CSS操作

jquery中css的操作 jqury中操作css有直接與間接兩種 直接的又有2種 鍵值對的方式 css property value 鍵值對對映的方式 css 這兩種直接在js中寫css屬性值 間接的有 在css檔案中先定義好要新增或移除的類,然後用.addclass 類名 為物件新增該css類,...

jquery框架 CSS操作

css css方法 css獲採樣式 h1 css h1 click function offset position scrolltop scrollleft offset獲取絕對定位座標 mydiv 123回到頂部特效 未實現 top position獲取相對父元素的座標 div1 div2 he...

jQuery 屬性操作和CSS 操作

addclass attr hasclass html removeattr removeclass toggleclass val css p css color 取得第乙個段落的 color 樣式屬性的值 selector css name,value 設定所有匹配元素的指定 css 屬性 se...