-
Notifications
You must be signed in to change notification settings - Fork 3
/
GoScroll.min.js
11 lines (11 loc) · 1.34 KB
/
GoScroll.min.js
1
2
3
4
5
6
7
8
9
10
11
/**
*
* @Name : GoScroll.js
* @Version : 1.0
* @Programmer : Max
* @Date : 2018-06-21
* @Released under : https://github.com/BaseMax/GoScrollJs/blob/master/LICENSE
* @Repository : https://github.com/BaseMax/GoScrollJs
*
**/
!function(n,a){"use strict";var e=function(t,o,l){var e=n.pageYOffset||a.documentElement.scrollTop||a.body.scrollTop||0,c=o-e,r=function(t){var o=i(t+=20,e,c,l);a.documentElement.scrollTop=o,a.body.scrollTop=o,t<l&&setTimeout(function(){r(t)},20)};r(0)},i=function(t,o,l,e){return(t/=e/2)<1?l/2*t*t+o:-l/2*((t-=1)*(t-2)-1)+o};n.goscroll={offset:50,go:function(t){var o,l=a.querySelector(t.getAttribute("data-scroll-go")).offsetTop;t.hasAttribute("data-scroll-offset")?l-=t.getAttribute("data-scroll-offset"):l-=50,o=t.hasAttribute("data-scroll-time")?t.getAttribute("data-scroll-time"):500,e(a.body,l,o)},goto:function(t){var o,l=t.getAttribute("data-scroll-to");t.hasAttribute("data-scroll-offset")?l-=t.getAttribute("data-scroll-offset"):l-=50,o=t.hasAttribute("data-scroll-time")?t.getAttribute("data-scroll-time"):500,e(a.body,l,o)}},n.addEventListener("load",function(){a.querySelectorAll("[data-scroll-go]").forEach(function(t){null===t.onclick&&(t.onclick=function(){n.goscroll.go(this)})}),a.querySelectorAll("[data-scroll-to]").forEach(function(t){null===t.onclick&&(t.onclick=function(){n.goscroll.goto(this)})})},!1)}(window,document);