this.length > 1
return this.each(function(index) {
$(this).wrapAll(
func ? structure.call(this, index) : clone ? dom.cloneNode(true) : dom)
})
},
wrapAll: function(structure) {
if (this[0]) {
//将要包裹的内容插入到第一条记录的前面,算是给structure定位围置
$(this[0]).before(structure = $(structure))
var children
// drill down to the inmost element
//取structure里的第一个子节点的最里层
while ((children = structure.children()).length) structure = children.first()
//将当前集合插入到最里层的节点里,达到wrapAll的目的
$(structure).append(this)
}
return this
},
//在匹配元素里的内容外包一层结构
wrapInner: function(structure) {
var func = isFunction(structure)
return this.each(function(index) {
//原理就是获取节点的内容,然后用structure将内容包起来,如果内容不存在,则直接将structure append到该节点
var self = $(this),
contents = self.contents(),
dom = func ? structure.call(this, index) : structure
contents.length ? contents.wrapAll(dom) : self.append(dom)
})
},
unwrap: function() {
//用子元素替换掉父级
this.parent().each(function() {
$(this).replaceWith($(this).children())
})
return this
},
//clone node
clone: function() {
return this.map(function() {
return this.cloneNode(true)
})
},
//隐藏集合
hide: function() {
return this.css("display", "none")
},
toggle: function(setting) {
return this.each(function() {
var el = $(this);
/*
这个setting取得作用就是控制显示与隐藏,并不切换,当它的值为true时,一直显示,false时,一直隐藏
这个地方的判断看上去有点绕,其实也简单,意思是说,当不给toogle参数时,根据元素的display是否等于none来决定显示或者隐藏元素
当给toogle参数,就没有切换效果了,只是简单的根据参数值来决定显示或隐藏。如果参数true,相当于show方法,false则相当于hide方法
*/
(setting === undefined ? el.css("display") == "none" : setting) ? el.show() : el.hide()
})
},
prev: function(selector) {
return $(this.pluck('previousElementSibling')).filter(selector
关键词:zepto是啥