0
(部分代碼)(jQuery);SO:這是什麼意思?我正在學習SO源代碼
這是什麼意思?
(function (a) {
function d(g) {
return typeof g == "object" ? g : {
top: g,
left: g
}
}
var b = a.scrollTo = function (g, e, f) {
a(window).scrollTo(g, e, f)
};
b.defaults = {
axis: "xy",
duration: parseFloat(a.fn.jquery) >= 1.3 ? 0 : 1
};
b.window = function() {
return a(window)._scrollable()
};
a.fn._scrollable = function() {
return this.map(function() {
if (!(!this.nodeName || a.inArray(this.nodeName.toLowerCase(), ["iframe", "#document", "html", "body"]) != -1)) return this;
var g = (this.contentWindow || this).document || this.ownerDocument || this;
return a.browser.safari || g.compatMode == "BackCompat" ? g.body : g.documentElement
})
};
a.fn.scrollTo = function (g, e, f) {
if (typeof e == "object") {
f = e;
e = 0
}
if (typeof f == "function") f = {
onAfter: f
};
if (g == "max") g = 9E9;
f = a.extend({}, b.defaults, f);
e = e || f.speed || f.duration;
f.queue = f.queue && f.axis.length > 1;
if (f.queue) e /= 2;
f.offset = d(f.offset);
f.over = d(f.over);
return this._scrollable().each(function() {
function k(w) {
j.animate(r, e, f.easing, w &&
function() {
w.call(this, g, f)
})
}
var h = this,
j = a(h),
i = g,
m, r = {},
u = j.is("html,body");
switch (typeof i) {
case "number":
case "string":
if (/^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(i)) {
i =
d(i);
break
}
i = a(i, this);
case "object":
if (i.is || i.style) m = (i = a(i)).offset()
}
a.each(f.axis.split(""), function (w, v) {
var q = v == "x" ? "Left" : "Top",
s = q.toLowerCase(),
y = "scroll" + q,
D = h[y],
H = b.max(h, v);
if (m) {
r[y] = m[s] + (u ? 0 : D - j.offset()[s]);
if (f.margin) {
r[y] -= parseInt(i.css("margin" + q)) || 0;
r[y] -= parseInt(i.css("border" + q + "Width")) || 0
}
r[y] += f.offset[s] || 0;
if (f.over[s]) r[y] += i[v == "x" ? "width" : "height"]() * f.over[s]
} else {
q = i[s];
r[y] = q.slice && q.slice(-1) == "%" ? parseFloat(q)/100 * H : q
}
if (/^\d+$/.test(r[y])) r[y] = r[y] <= 0 ? 0 : Math.min(r[y], H);
if (!w && f.queue) {
D != r[y] && k(f.onAfterFirst);
delete r[y]
}
});
k(f.onAfter)
}).end()
};
b.max = function (g, e) {
var f = e == "x" ? "Width" : "Height",
k = "scroll" + f;
if (!a(g).is("html,body")) return g[k] - a(g)[f.toLowerCase()]();
f = "client" + f;
var h = g.ownerDocument.documentElement,
j = g.ownerDocument.body;
return Math.max(h[k], j[k]) - Math.min(h[f], j[f])
}
})(jQuery);
在什麼情況下是這樣的代碼?你在哪裏找到它? – Marm0t 2010-10-25 12:46:40
加油!你真的期望有人向你一行一行解釋嗎?請提出更具體的問題。 – 2010-10-25 12:46:53
我的意思是(...)(jQuery)的目的是什麼?傳遞jQuery作爲這個函數的參數?擴展jQuery? – 2010-10-25 12:51:17