smoothscroll
Advanced tools
Comparing version 0.3.0 to 0.4.0
{ | ||
"name": "smoothscroll", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "A teeny tiny smooth scroll script with ease-in-out effect and no jQuery.", | ||
@@ -10,3 +10,8 @@ "main": "smoothscroll.js", | ||
"repository": "https://github.com/alicelieutier/smoothScroll.git", | ||
"keywords": [ "smooth scroll", "scroll", "no jQuery", "anchor" ], | ||
"keywords": [ | ||
"smooth scroll", | ||
"scroll", | ||
"no jQuery", | ||
"anchor" | ||
], | ||
"scripts": { | ||
@@ -13,0 +18,0 @@ "test": "echo \"Error: no test specified\" && exit 1" |
@@ -91,16 +91,18 @@ (function (root, smoothScroll) { | ||
var linkHandler = function(ev) { | ||
ev.preventDefault(); | ||
if (!ev.defaultPrevented) { | ||
ev.preventDefault(); | ||
if (location.hash !== this.hash) window.history.pushState(null, null, this.hash) | ||
// using the history api to solve issue #1 - back doesn't work | ||
// most browser don't update :target when the history api is used: | ||
// THIS IS A BUG FROM THE BROWSERS. | ||
// change the scrolling duration in this call | ||
var node = document.getElementById(this.hash.substring(1)) | ||
if(!node) return; // Do not scroll to non-existing node | ||
if (location.hash !== this.hash) window.history.pushState(null, null, this.hash) | ||
// using the history api to solve issue #1 - back doesn't work | ||
// most browser don't update :target when the history api is used: | ||
// THIS IS A BUG FROM THE BROWSERS. | ||
// change the scrolling duration in this call | ||
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) | ||
// this will cause the :target to be activated. | ||
}); | ||
smoothScroll(node, 500, function (el) { | ||
location.replace('#' + el.id) | ||
// this will cause the :target to be activated. | ||
}); | ||
} | ||
} | ||
@@ -107,0 +109,0 @@ |
@@ -1,1 +0,1 @@ | ||
(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}); | ||
(function(root,smoothScroll){"use strict";if(typeof define==="function"&&define.amd){define(smoothScroll)}else if(typeof exports==="object"&&typeof module==="object"){module.exports=smoothScroll()}else{root.smoothScroll=smoothScroll()}})(this,function(){"use strict";if(typeof window!=="object")return;if(document.querySelectorAll===void 0||window.pageYOffset===void 0||history.pushState===void 0){return}var getTop=function(element,start){if(element.nodeName==="HTML")return-start;return element.getBoundingClientRect().top+start};var easeInOutCubic=function(t){return t<.5?4*t*t*t:(t-1)*(2*t-2)*(2*t-2)+1};var position=function(start,end,elapsed,duration){if(elapsed>duration)return end;return start+(end-start)*easeInOutCubic(elapsed/duration)};var smoothScroll=function(el,duration,callback,context){duration=duration||500;context=context||window;var start=context.scrollTop||window.pageYOffset;if(typeof el==="number"){var end=parseInt(el)}else{var end=getTop(el,start)}var clock=Date.now();var requestAnimationFrame=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||function(fn){window.setTimeout(fn,15)};var step=function(){var elapsed=Date.now()-clock;if(context!==window){context.scrollTop=position(start,end,elapsed,duration)}else{window.scroll(0,position(start,end,elapsed,duration))}if(elapsed>duration){if(typeof callback==="function"){callback(el)}}else{requestAnimationFrame(step)}};step()};var linkHandler=function(ev){if(!ev.defaultPrevented){ev.preventDefault();if(location.hash!==this.hash)window.history.pushState(null,null,this.hash);var node=document.getElementById(this.hash.substring(1));if(!node)return;smoothScroll(node,500,function(el){location.replace("#"+el.id)})}};document.addEventListener("DOMContentLoaded",function(){var internal=document.querySelectorAll('a[href^="#"]:not([href="#"])'),a;for(var i=internal.length;a=internal[--i];){a.addEventListener("click",linkHandler,false)}});return smoothScroll}); |
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
141670
108