Giter Site home page Giter Site logo

mattiashaal / smoothy Goto Github PK

View Code? Open in Web Editor NEW
5.0 1.0 1.0 671 KB

A smooth-scroll plugin running with average speed or a set time.

Home Page: https://mattiashaal.github.io/smoothy/

License: MIT License

JavaScript 100.00%
smooth-scrolling smoothy smooth-scroll-plugins

smoothy's Introduction

Smoothy

Most smooth-scroll plugins out there are running on a set time. Which sometimes can behave badly if the distance is very short, results in mega slow scroll, or very long, results in mega fast scroll. Smoothy takes care of this by having settings for average speed and set time. Select animation type after your needs.

Getting Started

  1. Install
  2. Include script
  3. Include markup
  4. Settings
  5. Demo

Install

# via npm:
$ npm install smoothy

# via git clone:
$ git clone https://github.com/kaloja/smoothy

Include script

Ensure you're using the file in the dist directory, which contains compiled production-ready code. Place the script before the closing </body> tag. The src directory contains development code.

<script src="dist/smoothy.min.js"></script>

Include markup

<a href="#id"><!-- Link to target --></a>
...
<div id="id"><!-- Target element --></div>

Initialize Smoothy

Ensure you initialize Smoothy after its script file.

<script>
	smoothy.init();
</script>

Settings

Smoothy works right out of the box. But you can customize it after your needs, using its API. You can pass your settings and callbacks into Smoothy through the init() function.

smoothy.init({
	easing: 'easeInOutQuad',
	offset: 80,
	speed: 2000,
	callback: function() {
		console.log('Smoothy scroll animation is done');
	}
});

callback

Add a function that will be called when the scroll animation has been completed.

options: function | undefined => default: undefined

smoothy.init({
	callback: function() {
		console.log('Smoothy scroll animation is done');
	}
});

easing

A collection of easing patterns to choose from.

options: linear | easeInOutQuad | easeInOutCubic => default: linear

offset

Option to offset where the animation ends. If the user interface using a fixed header you can offset the headers height to avoid your target being hidden behind it.

default: 0

speed

Defines the average speed. Speed returns pixels per second.

default: 1000

time

Defines the animation time.

default: 500

type

Speed is the default animation type for Smoothy.

options: speed | time => default: speed

smoothy's People

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

olach

smoothy's Issues

Prevent on scroll

It would be great if the scrolling would stop if the user starts scrolling on his own.

Now it will continue scrolling the whole way even if the user tries to scroll on his own.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.