Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

smoothscroll

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

smoothscroll - npm Package Compare versions

Comparing version 0.2.1 to 0.2.2

2

package.json
{
"name": "smoothscroll",
"version": "0.2.1",
"version": "0.2.2",
"description": "A teeny tiny smooth scroll script with ease-in-out effect and no jQuery.",

@@ -5,0 +5,0 @@ "main": "smoothscroll.js",

@@ -18,2 +18,13 @@ smoothScroll

All your internal links will be tied to a smooth scroll.
If you want to call a smooth scroll from your code, you can now use the API by calling:
`window.smoothScroll(target, duration, callback, context)`
where:
* `target` is a `HTMLElement Object` from your document that you want to scroll to, or a numeric position on the page
* `duration` is the total duration of the scroll (optional, defaults to 500ms)
* `callback` is a function to be executed when the scrolling is over (optional)
* `context` is the scrolling context (optional, defaults to window, can be any `HTMLElement Object`)
Alternatively, you can install smoothscroll as a dependency using npm:

@@ -25,16 +36,20 @@

All your internal links will be tied to a smooth scroll.
If you want to call a smooth scroll from your code, you can now use the API by calling:
Example usage as a module, binding to a custom element:
`window.smoothScroll(target, duration, callback)`
```javascript
var smoothScroll = require('smoothscroll');
where:
* `target` is a `HTMLElement Object` from your document that you want to scroll to, or a numeric position on the page
* `duration` is the total duration of the scroll (optional, defaults to 500ms)
* `callback` is a function to be executed when the scrolling is over (optional)
var exampleBtn = document.querySelector('.example-button');
var exampleDestination = document.querySelector('.example-destination');
You can easily change the name of the global `smoothScroll` function returned by the script in the minified file, as it is the second word on the line.
// This function can easily be an onClick handler in React components
var handleClick = function(event) {
event.preventDefault();
Of course, if you want more personalisation, you should work with the unminified version of the script.
smoothScroll(exampleDestination);
};
exampleBtn.addEventListener('click', handleClick);
```
smoothscroll.js

@@ -66,2 +81,1 @@ -

This library is released under the MIT license.

@@ -53,4 +53,6 @@ (function (root, smoothScroll) {

// if the callback exist, it is called when the scrolling is finished
var smoothScroll = function(el, duration, callback){
// 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;

@@ -71,3 +73,9 @@

var elapsed = Date.now() - clock;
window.scroll(0, position(start, end, elapsed, duration));
if (context !== window) {
context.scrollTop = position(start, end, elapsed, duration);
}
else {
window.scroll(0, position(start, end, elapsed, duration));
}
if (elapsed > duration) {

@@ -74,0 +82,0 @@ if (typeof callback === 'function') {

@@ -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){o=o||500;var r=window.pageYOffset;if("number"==typeof t)var u=parseInt(t);else var u=e(t);var a=Date.now(),f=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||function(e){window.setTimeout(e,15)},d=function(){var e=Date.now()-a;window.scroll(0,n(r,u,e,o)),e>o?"function"==typeof i&&i(t):f(d)};d()},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";"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}});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc