summaryrefslogtreecommitdiff
path: root/js/core/smooth-scroll.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/core/smooth-scroll.js')
-rwxr-xr-xjs/core/smooth-scroll.js62
1 files changed, 62 insertions, 0 deletions
diff --git a/js/core/smooth-scroll.js b/js/core/smooth-scroll.js
new file mode 100755
index 0000000..789e426
--- /dev/null
+++ b/js/core/smooth-scroll.js
@@ -0,0 +1,62 @@
1/*! UIkit 2.26.4 | http://www.getuikit.com | (c) 2014 YOOtheme | MIT License */
2(function(UI) {
3
4 "use strict";
5
6 UI.component('smoothScroll', {
7
8 boot: function() {
9
10 // init code
11 UI.$html.on("click.smooth-scroll.uikit", "[data-uk-smooth-scroll]", function(e) {
12 var ele = UI.$(this);
13
14 if (!ele.data("smoothScroll")) {
15 var obj = UI.smoothScroll(ele, UI.Utils.options(ele.attr("data-uk-smooth-scroll")));
16 ele.trigger("click");
17 }
18
19 return false;
20 });
21 },
22
23 init: function() {
24
25 var $this = this;
26
27 this.on("click", function(e) {
28 e.preventDefault();
29 scrollToElement(UI.$(this.hash).length ? UI.$(this.hash) : UI.$("body"), $this.options);
30 });
31 }
32 });
33
34 function scrollToElement(ele, options) {
35
36 options = UI.$.extend({
37 duration: 1000,
38 transition: 'easeOutExpo',
39 offset: 0,
40 complete: function(){}
41 }, options);
42
43 // get / set parameters
44 var target = ele.offset().top - options.offset,
45 docheight = UI.$doc.height(),
46 winheight = window.innerHeight;
47
48 if ((target + winheight) > docheight) {
49 target = docheight - winheight;
50 }
51
52 // animate to target, fire callback when done
53 UI.$("html,body").stop().animate({scrollTop: target}, options.duration, options.transition).promise().done(options.complete);
54 }
55
56 UI.Utils.scrollToElement = scrollToElement;
57
58 if (!UI.$.easing.easeOutExpo) {
59 UI.$.easing.easeOutExpo = function(x, t, b, c, d) { return (t == d) ? b + c : c * (-Math.pow(2, -10 * t / d) + 1) + b; };
60 }
61
62})(UIkit);