// queue 的統一者
const queue_1 = {
name: "queue"
};
function t_1() {
$(queue_1).queue(function (next) {
$("#box_1").animate({
left: "+=5%"
}, {
duration: 1000,
queue: false,
complete: function () {
next();
}
})
});
}
2018年9月26日 星期三
2017年9月6日 星期三
jq 當遇到如 ie left=auto 時的處理方式
cur: function() {
debugger;
if ( this.elem[ this.prop ] != null && (!this.elem.style || this.elem.style[ this.prop ] == null) ) {
return this.elem[ this.prop ];
}
var parsed,
r = jQuery.css( this.elem, this.prop );
// Empty strings, null, undefined and "auto" are converted to 0,
// complex values such as "rotate(1rad)" are returned as is,
// simple values such as "10px" are parsed to Float.
return isNaN( parsed = parseFloat( r ) ) ? !r || r === "auto" ? 0 : r : parsed;
}
debugger;
if ( this.elem[ this.prop ] != null && (!this.elem.style || this.elem.style[ this.prop ] == null) ) {
return this.elem[ this.prop ];
}
var parsed,
r = jQuery.css( this.elem, this.prop );
// Empty strings, null, undefined and "auto" are converted to 0,
// complex values such as "rotate(1rad)" are returned as is,
// simple values such as "10px" are parsed to Float.
return isNaN( parsed = parseFloat( r ) ) ? !r || r === "auto" ? 0 : r : parsed;
}
2017年5月26日 星期五
$.closestChildren 找到符合過濾條件最接近的子孫
//for backbone(取代 find)
(function ($) {
// 找到符合過濾條件最接近的子孫
$.fn.closestChildren = function (selector) {
debugger;
var self = this;
this.each(function (i, dom) {
$find = $.closestChildren(dom, selector);
self[i] = $find.get(0);
});
/*------------------------------------*/
var resultList = this.toArray().filter(function (item) {
return (item != null);
});
for (var i = 0; i < this.length; i++) {
if (resultList[i]) {
this[i] = resultList[i];
} else {
delete this[i];
}
}
this.length = resultList.length;
return this;
};
/* ====================================================================== */
$.closestChildren = function (dom, selector) {
var domList = [];
var target = find(dom);
/* ---------------------------------- */
if (target.length) {
// 第一輪就找到
} else {
// 廣域搜尋
for (var i = 0; i < domList.length; i++) {
target = find(domList[i]);
if (target.length > 0) {
break;
}
}
}
/* ---------------------------------- */
function find(dom) {
var $findList = $(dom).children(selector);
if ($findList.length) {
// 有找到
} else {
// 沒找到
var childList = $(dom).children().toArray();
domList = domList.concat(childList);
}
return $findList;
}
domList = [];
return target;
};
})(jQuery);
(function ($) {
// 找到符合過濾條件最接近的子孫
$.fn.closestChildren = function (selector) {
debugger;
var self = this;
this.each(function (i, dom) {
$find = $.closestChildren(dom, selector);
self[i] = $find.get(0);
});
/*------------------------------------*/
var resultList = this.toArray().filter(function (item) {
return (item != null);
});
for (var i = 0; i < this.length; i++) {
if (resultList[i]) {
this[i] = resultList[i];
} else {
delete this[i];
}
}
this.length = resultList.length;
return this;
};
/* ====================================================================== */
$.closestChildren = function (dom, selector) {
var domList = [];
var target = find(dom);
/* ---------------------------------- */
if (target.length) {
// 第一輪就找到
} else {
// 廣域搜尋
for (var i = 0; i < domList.length; i++) {
target = find(domList[i]);
if (target.length > 0) {
break;
}
}
}
/* ---------------------------------- */
function find(dom) {
var $findList = $(dom).children(selector);
if ($findList.length) {
// 有找到
} else {
// 沒找到
var childList = $(dom).children().toArray();
domList = domList.concat(childList);
}
return $findList;
}
domList = [];
return target;
};
})(jQuery);
訂閱:
文章 (Atom)