@@ 1350-1410 (lines=61) @@ | ||
1347 | ||
1348 | })(UIkit2); |
|
1349 | ||
1350 | (function(UI) { |
|
1351 | ||
1352 | "use strict"; |
|
1353 | ||
1354 | UI.component('smoothScroll', { |
|
1355 | ||
1356 | boot: function() { |
|
1357 | ||
1358 | // init code |
|
1359 | UI.$html.on('click.smooth-scroll.uikit', '[data-uk-smooth-scroll]', function(e) { |
|
1360 | var ele = UI.$(this); |
|
1361 | ||
1362 | if (!ele.data('smoothScroll')) { |
|
1363 | var obj = UI.smoothScroll(ele, UI.Utils.options(ele.attr('data-uk-smooth-scroll'))); |
|
1364 | ele.trigger('click'); |
|
1365 | } |
|
1366 | ||
1367 | return false; |
|
1368 | }); |
|
1369 | }, |
|
1370 | ||
1371 | init: function() { |
|
1372 | ||
1373 | var $this = this; |
|
1374 | ||
1375 | this.on('click', function(e) { |
|
1376 | e.preventDefault(); |
|
1377 | scrollToElement(UI.$(this.hash).length ? UI.$(this.hash) : UI.$('body'), $this.options); |
|
1378 | }); |
|
1379 | } |
|
1380 | }); |
|
1381 | ||
1382 | function scrollToElement(ele, options) { |
|
1383 | ||
1384 | options = UI.$.extend({ |
|
1385 | duration: 1000, |
|
1386 | transition: 'easeOutExpo', |
|
1387 | offset: 0, |
|
1388 | complete: function(){} |
|
1389 | }, options); |
|
1390 | ||
1391 | // get / set parameters |
|
1392 | var target = ele.offset().top - options.offset, |
|
1393 | docheight = UI.$doc.height(), |
|
1394 | winheight = window.innerHeight; |
|
1395 | ||
1396 | if ((target + winheight) > docheight) { |
|
1397 | target = docheight - winheight; |
|
1398 | } |
|
1399 | ||
1400 | // animate to target, fire callback when done |
|
1401 | UI.$('html,body').stop().animate({scrollTop: target}, options.duration, options.transition).promise().done(options.complete); |
|
1402 | } |
|
1403 | ||
1404 | UI.Utils.scrollToElement = scrollToElement; |
|
1405 | ||
1406 | if (!UI.$.easing.easeOutExpo) { |
|
1407 | UI.$.easing.easeOutExpo = function(x, t, b, c, d) { return (t == d) ? b + c : c * (-Math.pow(2, -10 * t / d) + 1) + b; }; |
|
1408 | } |
|
1409 | ||
1410 | })(UIkit2); |
|
1411 | ||
1412 | (function(UI) { |
|
1413 |
@@ 2-62 (lines=61) @@ | ||
1 | /*! UIkit 2.27.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 | })(UIkit2); |
|
63 |