先給大家展示謝
jQuery.fn.css (propertyName [, value ]| object )(函數用於設定或傳回目前jQuery物件所匹配的元素的css樣式屬性值。如果需要刪除指定的css屬性,請使用函數將其值設為空字串("")
注意:1、如果省略了value參數,則表示取得屬性值;如果指定了該參數,則表示設定屬性值。 2、css()函數的所有"設定"操作針對的是當前jQuery物件所匹配的每一個元素;所有"讀取"操作只針對第一個匹配的元素。 )
jQuery.fn.offset([coordinatesObj])(設定或傳回目前符合元素(將content padding border看成一個整體)相對於目前文件的偏移,也就是相對於目前文件的座標。函數只對可見元素有效。 ()傳回的是相對於目前文件的座標,position()傳回的是相對於其定位的祖輩元素的座標。
jQuery.fn.position()(傳回目前符合元素(將content padding border margin看成一個整體)相對於其被定位的祖輩元素的偏移,也就是相對於被定位的祖輩元素的座標。此函數只對可見元素有效。 left屬性與top屬性。元素全部都是預設定位(static),那麼函數傳回的偏移位置與offset()函數相同)jQuery.fn.scrollLeft([ value ])(設定或傳回目前符合元素相對於水平捲軸左側的偏移。當一個元素的實際寬度超過其顯示區域的寬度時,在一定的設定下,瀏覽器會為此元素顯示對應的水平捲軸。
如果水平捲軸在最左側(也就是可見區域左側沒有被隱藏的內容),或者當前元素是不可水平滾動的,那麼scrollLeft()將返回0。對可見的和隱藏的元素均有效。 )
jQuery.fn.scrollTop([ value ])(設定或傳回目前符合元素相對於垂直捲軸頂部的偏移。當一個元素的實際高度超過其顯示區域的高度時,在一定的設定下,瀏覽器會為此元素顯示對應的垂直捲軸。可見區域之上沒有被隱藏的內容),或者當前元素是不可垂直滾動的,那麼scrollTop()將返回0。
jQuery.fn.height([ value ])(設定或傳回目前符合元素的高度。此高度值不包括元素的外邊距(margin)、內邊距(padding)、邊框(border)等部分的高度。
如果你要取得包括上述某部分在內的高度,請使用innerHeight()和outerHeight()。此函數屬於jQuery物件(實例),並且對不可見的元素仍然有效)
jQuery.fn.innerHeight([ value ])(設定或傳回目前符合元素的內高度。此高度值包括內邊距(padding),但不包含元素的外邊距(margin)、邊框(border)等部分的高度。
此函數屬於jQuery物件(實例),且對不可見的元素依然有效)
jQuery.fn.outerHeight([includeMargin])(設定或傳回目前符合元素的外高度。此高度值包括內邊距(padding) 、邊框(border),但不包含元素的外邊距(margin)部分的高度。
此函數屬於jQuery物件(實例),且對不可見的元素依然有效)
jQuery.fn.width([ value ])(描述:略)
jQuery.fn.innerWidth ([ value ])(描述:略)
jQuery.fn.outerWidth ([includeMargin])(描述:略)
借用孤月藍風上色的詳解圖
接下來分析部分函數。
a.jQuery.fn.offset分析
The method for obtaining offset is as follows (taking top as an example):
Offset.top = The position of elem from the top of the browser window. The rolled-up part of the top of the document – elem is top from the top border of the parent element.
jQuery processing becomes:
box = elem.getBoundingClientRect(); offset.top = box.top + ( win.pageYOffset || docElem.scrollTop ) - ( docElem.clientTop || 0 );
There is a difference between modern browsers such as IE8- and IE9. Use document.documentElement.getBoundingClientRect(); the top/left value of IE8- is -2px; the top/left value of other modern browsers is 0px; you can see Out of IE8-browser, the (2,2) coordinates of the window are used as the origin coordinates.
The browser will default to an 8px gap between the body and the window, so the top/left value obtained by using document.body.getBoundingClientRect(); is 8px.
The setting method of offset is as follows (taking top as an example):
It should be noted that before setting, if the current elem position is static, it must be set to relative to process
First get the value of the css feature top to be set to elem. The calculation method is
SetTop = (offset top value to be set – offset top value of the current element) css top feature value of elem
Then set setTop to the css top feature of elem.
jQuery’s processing becomes:
var curElem = jQuery( elem ), curOffset = curElem.offset(), curCSSTop = jQuery.css( elem, "top" ), props = {}, curPosition = {}, curTop; //如果top值为auto且position为absolute或fixed则需要计算当前elem的css特征top的值 if ( calculatePosition ) { curPosition = curElem.position(); curTop = curPosition.top; } else { curTop = parseFloat( curCSSTop ) || ; } if ( options.top != null ) { props.top = ( options.top - curOffset.top ) + curTop; } curElem.css( props );
b.jQuery.fn.position
Position can only be obtained but cannot be set. The acquisition method is as follows (taking top as an example):
Position.top = elem’s offsetTop – elem’s offsetTop of the positioned ancestor element – elem’s marginTop value
The top here is really the value of elem’s css attribute top. For jQuery, this elem regards the width padding border margin as a whole, so the final top is elem. The overall distance is determined as the distance between the top and inner edges of the ancestor elements.
jQuery processing becomes:
var offsetParent, offset, parentOffset = { top: 0, left: 0 }, elem = this[ 0 ]; //当元素为fixed定位是他的被定位的祖辈元素是window视窗(parentOffset = {top:0, left: 0} if ( jQuery.css( elem, "position" ) === "fixed" ) { //假设getBoundingClientRect可用 offset = elem.getBoundingClientRect(); } else { //获取offsetParent offsetParent = this.offsetParent(); // Get correct offsets offset = this.offset(); if ( !jQuery.nodeName( offsetParent[ 0 ], "html" ) ) { parentOffset = offsetParent.offset(); } //增加边框 parentOffset.top += jQuery.css( offsetParent[ 0 ], "borderTopWidth", true ); } return { top: offset.top - parentOffset.top - jQuery.css( elem, "marginTop", true ) };
The jQuery.fn.offsetParent() function inside gets the nearest ancestor positioned element.
offsetParent: function() { return this.map(function() { var offsetParent = this.offsetParent || document.documentElement; while ( offsetParent && ( !jQuery.nodeName( offsetParent, "html" ) && jQuery.css( offsetParent, "position") === "static" ) ) { offsetParent = offsetParent.offsetParent; } return offsetParent || document.documentElement; }); }
c.jQuery.fn.scrollLeft and jQuery.fn.scrollTop
It is relatively simple to obtain and set the scroll bar position by these two functions. To obtain scrollTop, there are only two functions window[pageYOffset] or elem[scrollTop]. To set it directly, use window[scrollTo] or elem[scrollTop]
The above content is the position and size operation of the jQuery 1.9.1 source code analysis series (Thirteen) introduced by the editor to you. I hope you like it.

JavaScript在瀏覽器和Node.js環境中運行,依賴JavaScript引擎解析和執行代碼。 1)解析階段生成抽象語法樹(AST);2)編譯階段將AST轉換為字節碼或機器碼;3)執行階段執行編譯後的代碼。

Python和JavaScript的未來趨勢包括:1.Python將鞏固在科學計算和AI領域的地位,2.JavaScript將推動Web技術發展,3.跨平台開發將成為熱門,4.性能優化將是重點。兩者都將繼續在各自領域擴展應用場景,並在性能上有更多突破。

Python和JavaScript在開發環境上的選擇都很重要。 1)Python的開發環境包括PyCharm、JupyterNotebook和Anaconda,適合數據科學和快速原型開發。 2)JavaScript的開發環境包括Node.js、VSCode和Webpack,適用於前端和後端開發。根據項目需求選擇合適的工具可以提高開發效率和項目成功率。

是的,JavaScript的引擎核心是用C語言編寫的。 1)C語言提供了高效性能和底層控制,適合JavaScript引擎的開發。 2)以V8引擎為例,其核心用C 編寫,結合了C的效率和麵向對象特性。 3)JavaScript引擎的工作原理包括解析、編譯和執行,C語言在這些過程中發揮關鍵作用。

JavaScript是現代網站的核心,因為它增強了網頁的交互性和動態性。 1)它允許在不刷新頁面的情況下改變內容,2)通過DOMAPI操作網頁,3)支持複雜的交互效果如動畫和拖放,4)優化性能和最佳實踐提高用戶體驗。

C 和JavaScript通過WebAssembly實現互操作性。 1)C 代碼編譯成WebAssembly模塊,引入到JavaScript環境中,增強計算能力。 2)在遊戲開發中,C 處理物理引擎和圖形渲染,JavaScript負責遊戲邏輯和用戶界面。

JavaScript在網站、移動應用、桌面應用和服務器端編程中均有廣泛應用。 1)在網站開發中,JavaScript與HTML、CSS一起操作DOM,實現動態效果,並支持如jQuery、React等框架。 2)通過ReactNative和Ionic,JavaScript用於開發跨平台移動應用。 3)Electron框架使JavaScript能構建桌面應用。 4)Node.js讓JavaScript在服務器端運行,支持高並發請求。

Python更適合數據科學和自動化,JavaScript更適合前端和全棧開發。 1.Python在數據科學和機器學習中表現出色,使用NumPy、Pandas等庫進行數據處理和建模。 2.Python在自動化和腳本編寫方面簡潔高效。 3.JavaScript在前端開發中不可或缺,用於構建動態網頁和單頁面應用。 4.JavaScript通過Node.js在後端開發中發揮作用,支持全棧開發。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

PhpStorm Mac 版本
最新(2018.2.1 )專業的PHP整合開發工具

ZendStudio 13.5.1 Mac
強大的PHP整合開發環境

DVWA
Damn Vulnerable Web App (DVWA) 是一個PHP/MySQL的Web應用程序,非常容易受到攻擊。它的主要目標是成為安全專業人員在合法環境中測試自己的技能和工具的輔助工具,幫助Web開發人員更好地理解保護網路應用程式的過程,並幫助教師/學生在課堂環境中教授/學習Web應用程式安全性。 DVWA的目標是透過簡單直接的介面練習一些最常見的Web漏洞,難度各不相同。請注意,該軟體中

Atom編輯器mac版下載
最受歡迎的的開源編輯器

記事本++7.3.1
好用且免費的程式碼編輯器