Zepto basic knowledge (3), zepto basic knowledge
41.Height
Height () type: number
Height (value) type: self
Height (function (index, oldHeight) {...}) type: self
Obtains the height of the first element in the object set, or sets the height of all elements in the object set.
$ ('# Foo'). height () // 123
$ (Window). height () /// 838 (viewport height)
$ (Document). height () // 22302
42.Hide
Hide () type: self
You can hide the elements in the object set by setting the display attribute of css to none.
43.Html
Html () type: string
Html (content) type: self
Html (function (index, oldHtml) {...}) type: self
Obtains or sets the HTML content of elements in an object set. If the content parameter is not specified, the first yuans in the object set is returned.
InnerHtml. When the content parameter is specified, use gas to replace the content of each element in the object set.
$ ('. Comment p'0000.html (function (idx, oldHtml ){
Return oldHtml. replace (/(^ | \ W) @ (\ w {1, 15})/g,
'$1 @ <a href = "http://twitter.com/#2"> $2 </a> ')
})
44.Index
Index ([element]) type: number
Obtains the index value of an element. If the element parameter is not provided, the current element position in the sibling node is returned.
When the parameter is given, it returns its position in the current object set. If this element is not found,-1 is returned.
$ ('Li: nth-child (2) '). index () // 1
45.IndexOf
IndexOf (element, [fromIndex]) type: number
Obtains the index value of an element in the current object set (starting from 0 ). If the formindex parameter is specified, the system returns a 0-based index starting from this position. If no index is found, the system returns-1.
This is a Zepto method, not a jquer api.
46.InsertAfter
InsertAfter (target) type: self
Insert the elements in the set to the end of the specified target element (external insertion), which is a bit like after. This is the opposite when used.
$ ('<P> Emphasis mine </p>'). insertAter ('blocjquote ')
47.InsertBefore
InsertBefore (target) Type
Insert the elements in the set to the front of the specified target element (external insertion ).
$ ('<P> see the following talble </p>'). nsertBefore (table)
48.Is
Is (selector) type: boolean
Determine whether the first element in the current Element Set conforms to the css selector. For non-standard selectors that support jquery, the options are as follows: visible is included in the optional "selector" module.
49.Last
Last () type: collection
Obtains the last element of an object set.
$ ('Lil'). last ()
50.Map
Map (function (index, item) {...}) type: collection
Traverses all elements in an object set. Create a new set object by traversing the return value of the function. In the traversal function, this
The key points to the items in the current loop. The traversal returns null and undefined, and the traversal ends.
Elements, map (function () {return $ (this). text ()}). get (). join (',')
51.Next
Next () type: collection
Next (selector) type: collection
Obtains the next sibling node of each element in an object set (filtering selector can be selected)
$ ('Dl dt '). next ()
52.Not
Not (selector) type: collection
Not (collection) type: collection
Not (function (index) {...}) collection
Filter the current object set to obtain a new object set. The elements in the set cannot match the css selector. If the other parameter is a Zepto object set, the elements in the returned Zepto object are not included in this parameter.
In a Number object, if a parameter is a function that only contains elements when the number is executed as false, the this keyword of the function points to the current loop element.
53.Offset
Offset () type: object
Offset (coordinates) type: selft
Offset (function (index, oldOffset) {...}) type: self
Obtain the position of the document corresponding to the current element. Returns an object containing the top left width height
When a left or top object is given, these values are used to locate each element in the set relative to the document.
54.OffsetParent
OffsetParent () type: collection
Find the first located ancestor element, which means that the de pasition attribute value in its css is relative absolute fixed
55.Parent
Parent ([selector]) type: collection
Obtain the direct parent element of each element in the object set. If the css selector parameter is used to filter out elements that meet the condition.
56.Parents
Parents ([selector]) type: collection
Obtain all the ancestor elements of each element in the object set. If the css selector parameter is given, filter out the elements that meet the condition.
If you want to obtain the direct parent element, use parent,
$('H1 '). parents () // [<div # container>, <body>,
57.Pluck
Pluck (property) type: array
Obtains the attribute values of each element in an object set. If the returned value is null or undefined, it is worth filtering out.
$ ('Body> * '). pluck ("nodeName ")
// => ["DIV", "SCRIPT"]
$. Fn. next = function (){
Return $ (this. pluck ('nextelementsibling '))
}
This is a Zepto method, not a jquery api
58.Position
Position () type: object
Obtains the position of the first element in an object set. This method is useful when an absolutely located element approaches another element.
Var pos = element. position ()
// Position a tooltip relative to the element
Certificate ('{tooltip'}.css ({
Position: 'absolute ',
Top: pos. top-30,
Left: pos. left
})
59.Prepend
Prepend (content) type: self
Insert the parameter content to the front of each element (insert the element content ). You can try html string fragments, a dom node, or an array of nodes to insert d.
$ ('Ul '). prepend (' <li> first list item </li> ')
60.PrependTo
PrependTo (target) type: self
Insert all elements to the front of the target (insert within the element). This is a bit like a prenpend, but it is the opposite.
$ ('<Li> first list item </li>'). prependTo ('ul ')