Skip to content

Commit c8caf1d

Browse files
authored
Create smoothScroll.js
1 parent b877c3a commit c8caf1d

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

Weby/Frontend/smoothScroll.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Dependencies: jQuery
2+
3+
$(document).ready(function(){
4+
$("a").on('click', function(event) {
5+
if (this.hash !== "") {
6+
event.preventDefault();
7+
var hash = this.hash;
8+
$('html, body').animate({
9+
scrollTop: $(hash).offset().top
10+
}, 800, function(){
11+
window.location.hash = hash;
12+
});
13+
}
14+
});
15+
});
16+
$(document).ready(function(){
17+
"use strict";
18+
$.easing.easeInOutExpo = function (x, t, b, c, d) {
19+
if (t===0) {return b;}
20+
if (t===d) {return b+c;}
21+
if ((t/=d/2) < 1) { return c/2 * Math.pow(2, 10 * (t - 1)) + b;
22+
} else {
23+
return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
24+
}
25+
};
26+
27+
$('a').bind('click', function(event) {
28+
var $ele = $(this);
29+
$('html, body').animate({
30+
scrollTop: ($($ele.attr('href')).offset().top)
31+
}, 1450, 'easeInOutExpo');
32+
event.preventDefault();
33+
});
34+
});
35+
36+
window.location.hash = this.hash;

0 commit comments

Comments
 (0)