国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

juqery 學(xué)習(xí)之六 CSS--css、位置、寬高

2019-11-20 23:57:00
字體:
供稿:網(wǎng)友
css(name)
訪問第一個(gè)匹配元素的樣式屬性。

--------------------------------------------------------------------------------

Return a style property on the first matched element.
返回值
String

參數(shù)
name (String) : 要訪問的屬性名稱

示例
取得第一個(gè)段落的color樣式屬性的值。

jQuery 代碼:

$("p").css("color");
-------------------------------------------------------------------------------------------------------------------------------------------------
css(properties)
把一個(gè)“名/值對(duì)”對(duì)象設(shè)置為所有匹配元素的樣式屬性。
這是一種在所有匹配的元素上設(shè)置大量樣式屬性的最佳方式。

--------------------------------------------------------------------------------

Set a key/value object as style properties to all matched elements.
This is the best way to set several style properties on all matched elements.
返回值
jQuery

參數(shù)
properties (Map) : 要設(shè)置為樣式屬性的名/值對(duì)

示例
將所有段落的字體顏色設(shè)為紅色并且背景為藍(lán)色。

jQuery 代碼:

$("p").css({ color: "#ff0011", background: "blue" });

--------------------------------------------------------------------------------

如果屬性名包含 "-"的話,必須使用引號(hào):

jQuery 代碼:

$("p").css({ "margin-left": "10px", "background-color": "blue" });
-------------------------------------------------------------------------------------------------------------------------------------------------
css(name,value)
在所有匹配的元素中,設(shè)置一個(gè)樣式屬性的值。
數(shù)字將自動(dòng)轉(zhuǎn)化為像素值

--------------------------------------------------------------------------------

Set a single style property to a value on all matched elements.
If a number is provided, it is automatically converted into a pixel value.
返回值
jQuery

參數(shù)
name (value) : 屬性名

value (String, Number) : 屬性值

示例
將所有段落字體設(shè)為紅色

jQuery 代碼:

$("p").css("color","red");
-------------------------------------------------------------------------------------------------------------------------------------------------
offset()
獲取匹配元素在當(dāng)前視口的相對(duì)偏移。
返回的對(duì)象包含兩個(gè)整形屬性:top 和 left。此方法只對(duì)可見元素有效。

--------------------------------------------------------------------------------

Get the current offset of the first matched element relative to the viewport.
The returned object contains two Integer properties, top and left. The method works only with visible elements.
返回值
Object{top,left}

示例
獲取第二段的偏移

HTML 代碼:

<p>Hello</p><p>2nd Paragraph</p>
jQuery 代碼:

var p = $("p:last");
var offset = p.offset();
p.html( "left: " + offset.left + ", top: " + offset.top );
結(jié)果:

<p>Hello</p><p>left: 0, top: 35</p>
-------------------------------------------------------------------------------------------------------------------------------------------------
height()
取得第一個(gè)匹配元素當(dāng)前計(jì)算的高度值(px)。
在 jQuery 1.2 以后可以用來獲取 window 和 document 的高

--------------------------------------------------------------------------------

Get the current computed, pixel, height of the first matched element.
In jQuery 1.2, this method is able to find the height of the window and document.
返回值
Integer

示例
獲取第一段的高

jQuery 代碼:

$("p").height();

--------------------------------------------------------------------------------

獲取文檔的高

jQuery 代碼:

$(document).height();
把所有段落的高設(shè)為 20:

jQuery 代碼:

$("p").height(20);
-------------------------------------------------------------------------------------------------------------------------------------------------
width()
取得第一個(gè)匹配元素當(dāng)前計(jì)算的寬度值(px)。
在 jQuery 1.2 以后可以用來獲取 window 和 document 的寬

--------------------------------------------------------------------------------

Get the current computed, pixel, width of the first matched element.
In jQuery 1.2, this method is able to find the width of the window and document.
返回值
Integer

示例
獲取第一段的寬

jQuery 代碼:

$("p").width();

--------------------------------------------------------------------------------

獲取當(dāng)前窗口的寬

jQuery 代碼:

$(window).width();
將所有段落的寬設(shè)為 20:

jQuery 代碼:

$("p").width(20);
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 开江县| 鄂托克旗| 高雄市| 郎溪县| 常山县| 神木县| 安新县| 奉化市| 康马县| 久治县| 临夏市| 洛川县| 达尔| 广南县| 布尔津县| 灵石县| 白银市| 西和县| 松原市| 盐亭县| 温州市| 湖南省| 天全县| 固原市| 建瓯市| 花莲市| 安达市| 长岛县| 易门县| 扎兰屯市| 巴林右旗| 当涂县| 峨山| 乐安县| 抚远县| 浦县| 汾西县| 安化县| 剑河县| 图木舒克市| 屏东县|