Coder Social home page Coder Social logo

sliding-scroll's Introduction

Sliding-Scroll

A minimal pure JavaScript smooth scrolling function.

Scroll smoothly over time to a given absolute scroll position defined by the top and left properties.
If the top or left scroll position is omitted it will fallback to the current scroll position.

duration: Scroll duration in milliseconds; defaults to 0 (no transition)
element: The html element that should be scrolled; defaults to the main scrolling element
easingFunction: Defines the scrolling rate over time; defaults to ease in and out sin.
You can either use one of the predefined functions from EASING_FUNCTIONS or a custom one.

Smooth scroll to function

function smoothScrollTo({
  top,
  left,
  duration = 0,
  element = document.scrollingElement,
  easingFunction = EASING_FUNCTIONS.slowInSlowOut
})

Additional convenience functions

Scroll to the top of the main page

smoothScrollToTop({
    duration = 0,
    easingFunction = EASING_FUNCTIONS.slowInSlowOut
})

Scroll to the bottom of the main page

smoothScrollToBottom({
    duration = 0,
    easingFunction = EASING_FUNCTIONS.slowInSlowOut
})

Scroll to a specific element in the main page.

smoothScrollToElement(element, {
  duration, easingFunction,
  offsetTop = 0,
  offsetLeft = 0
})

Scroll to an element with a specific id in the main page.

smoothScrollToId(id, {
  duration, easingFunction,
  offsetTop = 0,
  offsetLeft = 0,
})

sliding-scroll's People

Contributors

octopus3 avatar robbendebiene avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

sliding-scroll's Issues

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.