237 lines
6.5 KiB
JavaScript
237 lines
6.5 KiB
JavaScript
//https://gist.github.com/motorcitymobi/4597044
|
|
|
|
/**
|
|
* SmoothScroll
|
|
* This helper script created by DWUser.com. Copyright 2013 DWUser.com.
|
|
* Dual-licensed under the GPL and MIT licenses.
|
|
* All individual scripts remain property of their copyrighters.
|
|
* Date: 10-Sep-2013
|
|
* Version: 1.0.1
|
|
*/
|
|
if (!window["jQuery"])
|
|
alert(
|
|
"The jQuery library must be included before the smoothscroll.js file. The plugin will not work propery."
|
|
);
|
|
|
|
/**
|
|
* Copyright (c) 2007 Ariel Flesler - aflesler ○ gmail • com | https://github.com/flesler
|
|
* Licensed under MIT
|
|
* @author Ariel Flesler
|
|
* @version 2.1.2
|
|
*/
|
|
(function(f) {
|
|
"use strict";
|
|
"function" === typeof define && define.amd
|
|
? define(["jquery"], f)
|
|
: "undefined" !== typeof module && module.exports
|
|
? (module.exports = f(require("jquery")))
|
|
: f(jQuery);
|
|
})(function($) {
|
|
"use strict";
|
|
function n(a) {
|
|
return (
|
|
!a.nodeName ||
|
|
-1 !==
|
|
$.inArray(a.nodeName.toLowerCase(), [
|
|
"iframe",
|
|
"#document",
|
|
"html",
|
|
"body"
|
|
])
|
|
);
|
|
}
|
|
function h(a) {
|
|
return $.isFunction(a) || $.isPlainObject(a) ? a : { top: a, left: a };
|
|
}
|
|
var p = ($.scrollTo = function(a, d, b) {
|
|
return $(window).scrollTo(a, d, b);
|
|
});
|
|
p.defaults = { axis: "xy", duration: 0, limit: !0 };
|
|
$.fn.scrollTo = function(a, d, b) {
|
|
"object" === typeof d && ((b = d), (d = 0));
|
|
"function" === typeof b && (b = { onAfter: b });
|
|
"max" === a && (a = 9e9);
|
|
b = $.extend({}, p.defaults, b);
|
|
d = d || b.duration;
|
|
var u = b.queue && 1 < b.axis.length;
|
|
u && (d /= 2);
|
|
b.offset = h(b.offset);
|
|
b.over = h(b.over);
|
|
return this.each(function() {
|
|
function k(a) {
|
|
var k = $.extend({}, b, {
|
|
queue: !0,
|
|
duration: d,
|
|
complete:
|
|
a &&
|
|
function() {
|
|
a.call(q, e, b);
|
|
}
|
|
});
|
|
r.animate(f, k);
|
|
}
|
|
if (null !== a) {
|
|
var l = n(this),
|
|
q = l ? this.contentWindow || window : this,
|
|
r = $(q),
|
|
e = a,
|
|
f = {},
|
|
t;
|
|
switch (typeof e) {
|
|
case "number":
|
|
case "string":
|
|
if (/^([+-]=?)?\d+(\.\d+)?(px|%)?$/.test(e)) {
|
|
e = h(e);
|
|
break;
|
|
}
|
|
e = l ? $(e) : $(e, q);
|
|
case "object":
|
|
if (e.length === 0) return;
|
|
if (e.is || e.style) t = (e = $(e)).offset();
|
|
}
|
|
var v = ($.isFunction(b.offset) && b.offset(q, e)) || b.offset;
|
|
$.each(b.axis.split(""), function(a, c) {
|
|
var d = "x" === c ? "Left" : "Top",
|
|
m = d.toLowerCase(),
|
|
g = "scroll" + d,
|
|
h = r[g](),
|
|
n = p.max(q, c);
|
|
t
|
|
? ((f[g] = t[m] + (l ? 0 : h - r.offset()[m])),
|
|
b.margin &&
|
|
((f[g] -= parseInt(e.css("margin" + d), 10) || 0),
|
|
(f[g] -= parseInt(e.css("border" + d + "Width"), 10) || 0)),
|
|
(f[g] += v[m] || 0),
|
|
b.over[m] &&
|
|
(f[g] += e["x" === c ? "width" : "height"]() * b.over[m]))
|
|
: ((d = e[m]),
|
|
(f[g] =
|
|
d.slice && "%" === d.slice(-1)
|
|
? (parseFloat(d) / 100) * n
|
|
: d));
|
|
b.limit &&
|
|
/^\d+$/.test(f[g]) &&
|
|
(f[g] = 0 >= f[g] ? 0 : Math.min(f[g], n));
|
|
!a &&
|
|
1 < b.axis.length &&
|
|
(h === f[g] ? (f = {}) : u && (k(b.onAfterFirst), (f = {})));
|
|
});
|
|
k(b.onAfter);
|
|
}
|
|
});
|
|
};
|
|
p.max = function(a, d) {
|
|
var b = "x" === d ? "Width" : "Height",
|
|
h = "scroll" + b;
|
|
if (!n(a)) return a[h] - $(a)[b.toLowerCase()]();
|
|
var b = "client" + b,
|
|
k = a.ownerDocument || a.document,
|
|
l = k.documentElement,
|
|
k = k.body;
|
|
return Math.max(l[h], k[h]) - Math.min(l[b], k[b]);
|
|
};
|
|
$.Tween.propHooks.scrollLeft = $.Tween.propHooks.scrollTop = {
|
|
get: function(a) {
|
|
return $(a.elem)[a.prop]();
|
|
},
|
|
set: function(a) {
|
|
var d = this.get(a);
|
|
if (a.options.interrupt && a._last && a._last !== d)
|
|
return $(a.elem).stop();
|
|
var b = Math.round(a.now);
|
|
d !== b && ($(a.elem)[a.prop](b), (a._last = this.get(a)));
|
|
}
|
|
};
|
|
return p;
|
|
});
|
|
|
|
/**
|
|
* Copyright (c) 2007 Ariel Flesler - aflesler<a>gmail<d>com | https://github.com/flesler
|
|
* Licensed under MIT
|
|
* @author Ariel Flesler
|
|
* @version 2.0.0
|
|
*/
|
|
!(function(e) {
|
|
"function" == typeof define && define.amd ? define(["jquery"], e) : e(jQuery);
|
|
})(function(e) {
|
|
function t(t, o, n) {
|
|
var i = o.hash.slice(1),
|
|
a = document.getElementById(i) || document.getElementsByName(i)[0];
|
|
if (a) {
|
|
t && t.preventDefault();
|
|
var l = e(n.target);
|
|
if (
|
|
!(
|
|
(n.lock && l.is(":animated")) ||
|
|
(n.onBefore && !1 === n.onBefore(t, a, l))
|
|
)
|
|
) {
|
|
if ((n.stop && l.stop(!0), n.hash)) {
|
|
var r = a.id === i ? "id" : "name",
|
|
s = e("<a> </a>")
|
|
.attr(r, i)
|
|
.css({
|
|
position: "absolute",
|
|
top: e(window).scrollTop(),
|
|
left: e(window).scrollLeft()
|
|
});
|
|
(a[r] = ""),
|
|
e("body").prepend(s),
|
|
(location.hash = o.hash),
|
|
s.remove(),
|
|
(a[r] = i);
|
|
}
|
|
l.scrollTo(a, n).trigger("notify.serialScroll", [a]);
|
|
}
|
|
}
|
|
}
|
|
var o = location.href.replace(/#.*/, ""),
|
|
n = (e.localScroll = function(t) {
|
|
e("body").localScroll(t);
|
|
});
|
|
return (
|
|
(n.defaults = {
|
|
duration: 1e3,
|
|
axis: "y",
|
|
event: "click",
|
|
stop: !0,
|
|
target: window,
|
|
autoscroll: !0
|
|
}),
|
|
(e.fn.localScroll = function(i) {
|
|
function a() {
|
|
return (
|
|
!!this.href &&
|
|
!!this.hash &&
|
|
this.href.replace(this.hash, "") === o &&
|
|
(!i.filter || e(this).is(i.filter))
|
|
);
|
|
}
|
|
return (
|
|
(i = e.extend({}, n.defaults, i)).autoscroll &&
|
|
i.hash &&
|
|
location.hash &&
|
|
(i.target && window.scrollTo(0, 0), t(0, location, i)),
|
|
i.lazy
|
|
? this.on(i.event, "a,area", function(e) {
|
|
a.call(this) && t(e, this, i);
|
|
})
|
|
: this.find("a,area")
|
|
.filter(a)
|
|
.bind(i.event, function(e) {
|
|
t(e, this, i);
|
|
})
|
|
.end()
|
|
.end()
|
|
);
|
|
}),
|
|
(n.hash = function() {}),
|
|
n
|
|
);
|
|
});
|
|
|
|
// Initialize all .smoothScroll links
|
|
jQuery(function($) {
|
|
$.localScroll({ filter: ".smoothScroll" });
|
|
});
|