smoothscroll
Advanced tools
Comparing version 0.2.2 to 0.3.0
{ | ||
"name": "smoothscroll", | ||
"version": "0.2.2", | ||
"version": "0.3.0", | ||
"description": "A teeny tiny smooth scroll script with ease-in-out effect and no jQuery.", | ||
@@ -5,0 +5,0 @@ "main": "smoothscroll.js", |
@@ -30,6 +30,6 @@ (function (root, smoothScroll) { | ||
// Get the top position of an element in the document | ||
var getTop = function(element) { | ||
var getTop = function(element, start) { | ||
// return value of html.getBoundingClientRect().top ... IE : 0, other browsers : -pageYOffset | ||
if(element.nodeName === 'HTML') return -window.pageYOffset | ||
return element.getBoundingClientRect().top + window.pageYOffset; | ||
if(element.nodeName === 'HTML') return -start | ||
return element.getBoundingClientRect().top + start | ||
} | ||
@@ -54,7 +54,7 @@ // ease in out function thanks to: | ||
// if the callback exist, it is called when the scrolling is finished | ||
// if context is set then scroll that element, else scroll window | ||
// if context is set then scroll that element, else scroll window | ||
var smoothScroll = function(el, duration, callback, context){ | ||
duration = duration || 500; | ||
context = context || window; | ||
var start = window.pageYOffset; | ||
var start = context.scrollTop || window.pageYOffset; | ||
@@ -64,3 +64,3 @@ if (typeof el === 'number') { | ||
} else { | ||
var end = getTop(el); | ||
var end = getTop(el, start); | ||
} | ||
@@ -76,6 +76,6 @@ | ||
if (context !== window) { | ||
context.scrollTop = position(start, end, elapsed, duration); | ||
context.scrollTop = position(start, end, elapsed, duration); | ||
} | ||
else { | ||
window.scroll(0, position(start, end, elapsed, duration)); | ||
window.scroll(0, position(start, end, elapsed, duration)); | ||
} | ||
@@ -102,3 +102,6 @@ | ||
// change the scrolling duration in this call | ||
smoothScroll(document.getElementById(this.hash.substring(1)), 500, function(el) { | ||
var node = document.getElementById(this.hash.substring(1)) | ||
if(!node) return; // Do not scroll to non-existing node | ||
smoothScroll(node, 500, function(el) { | ||
location.replace('#' + el.id) | ||
@@ -105,0 +108,0 @@ // this will cause the :target to be activated. |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"use strict";"function"==typeof define&&define.amd?define(t):"object"==typeof exports&&"object"==typeof module?module.exports=t():e.smoothScroll=t()}(this,function(){"use strict";if("object"==typeof window&&void 0!==document.querySelectorAll&&void 0!==window.pageYOffset&&void 0!==history.pushState){var e=function(e){return"HTML"===e.nodeName?-window.pageYOffset:e.getBoundingClientRect().top+window.pageYOffset},t=function(e){return.5>e?4*e*e*e:(e-1)*(2*e-2)*(2*e-2)+1},n=function(e,n,o,i){return o>i?n:e+(n-e)*t(o/i)},o=function(t,o,i,r){o=o||500,r=r||window;var u=window.pageYOffset;if("number"==typeof t)var a=parseInt(t);else var a=e(t);var d=Date.now(),f=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||function(e){window.setTimeout(e,15)},s=function(){var e=Date.now()-d;r!==window?r.scrollTop=n(u,a,e,o):window.scroll(0,n(u,a,e,o)),e>o?"function"==typeof i&&i(t):f(s)};s()},i=function(e){e.preventDefault(),location.hash!==this.hash&&window.history.pushState(null,null,this.hash),o(document.getElementById(this.hash.substring(1)),500,function(e){location.replace("#"+e.id)})};return document.addEventListener("DOMContentLoaded",function(){for(var e,t=document.querySelectorAll('a[href^="#"]:not([href="#"])'),n=t.length;e=t[--n];)e.addEventListener("click",i,!1)}),o}}); | ||
(function(e,t){"use strict";typeof define=="function"&&define.amd?define(t):typeof exports=="object"&&typeof module=="object"?module.exports=t():e.smoothScroll=t()})(this,function(){"use strict";if(typeof window!="object")return;if(document.querySelectorAll===void 0||window.pageYOffset===void 0||history.pushState===void 0)return;var e=function(e,t){return e.nodeName==="HTML"?-t:e.getBoundingClientRect().top+t},t=function(e){return e<.5?4*e*e*e:(e-1)*(2*e-2)*(2*e-2)+1},n=function(e,n,r,i){return r>i?n:e+(n-e)*t(r/i)},r=function(t,r,i,s){r=r||500,s=s||window;var o=s.scrollTop||window.pageYOffset;if(typeof t=="number")var u=parseInt(t);else var u=e(t,o);var a=Date.now(),f=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||function(e){window.setTimeout(e,15)},l=function(){var e=Date.now()-a;s!==window?s.scrollTop=n(o,u,e,r):window.scroll(0,n(o,u,e,r)),e>r?typeof i=="function"&&i(t):f(l)};l()},i=function(e){e.preventDefault(),location.hash!==this.hash&&window.history.pushState(null,null,this.hash);var t=document.getElementById(this.hash.substring(1));if(!t)return;r(t,500,function(e){location.replace("#"+e.id)})};return document.addEventListener("DOMContentLoaded",function(){var e=document.querySelectorAll('a[href^="#"]:not([href="#"])'),t;for(var n=e.length;t=e[--n];)t.addEventListener("click",i,!1)}),r}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
140945
98