npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

smooth-scrolling

v2.3.12

Published

Smooth is a small JavaScript module based on VirtualScroll to create smooth scrolling and parallax effects on scroll.

Downloads

402

Readme

smooth

Smooth is a small JavaScript module based on VirtualScroll to create smooth scrolling and parallax effects on scroll. It works both with fake scrollbars and native scrolling.

Usage

npm install smooth-scrolling

import Smooth from 'smooth-scrolling'

const section = document.querySelector('.vs-section')
const smooth = new Smooth({
  native: true,
  section: section,
  ease: 0.1
})

smooth.init()

Options

  • listener: on-scroll events listener & parent container for all elements
  • direction : vertical or horizontal scrolling behavior
  • native: use the default scrollbar
  • section : the element to transform
  • ease : the easing value (usually between 0 and 1)
  • vs : you can pass some option for virtuall-scroll: limitInertia, mouseMultiplier, etc
  • preload : if set to false, there will be no resize function called after all images loaded
  • noscrollbar : if using virtual-scroll and set to true, it will not build a custom scrollbar
  • callback: function called on requestAnimationFrame

Methods

smooth.init()

Will add all event listeners and DOM elements.

smooth.on()

Will listen to either window scroll event (if native), otherwise VirtualScroll

smooth.off()

Will stop listening to onscroll/wheel events.

smooth.destroy()

Will remove all event listeners and DOM elements.

smooth.scrollTo(offset)

Basic scrollTo function.

Extends Smooth

import Smooth from 'smooth-scrolling'

class Custom extends Smooth {
  
  constructor(opt = {}) {
    super(opt)
    this.dom.section = opt.section
    this.dom.opacity = opt.opacity
  }
  
  run() {
    super.run()
    
    const current = Math.round(Math.abs(this.vars.current))
    const opacity = Math.max(0, Math.min(1 - current / (this.vars.height * .5), 1))
    
    this.dom.opacity.style.opacity = opacity.toFixed(2)
    this.dom.section.style[this.prefix] = this.getTransform(-this.vars.current.toFixed(2))
  }

  resize() {
    this.vars.bounding = this.dom.section.getBoundingClientRect().height - this.vars.height
    super.resize()
  }
}

export default Custom
// ...and later on
import Custom from './custom-smooth-scrolling'

const section = document.querySelector('.vs-section')
const opacity = document.querySelector('.vs-opacity')

const smooth = new Custom({
  section: section,
  opacity: opacity,
  ease: 0.1
})

smooth.init()

Development

git clone [email protected]:baptistebriel/smooth-scrolling.git

cd smooth-scrolling/ && npm i && npm run dev

You can use [http-server](https://www.npmjs.com/package/http-server) or MAMP to preview the demos.

Demos

npm run demo-parallax

npm run demo-parallax-page

npm run demo-horizontal

npm run demo-native-horizontal

npm run demo-opacity

npm run demo-scale

npm run demo-split

npm run demo-performances

Examples

Further understanding

If you didn't already read the tutorial, I highly recommend it. Smooth.js is basically what's explained on the blog post. I just needed a simple script to get things done without having to write lots of code every time I wanted to use this technique.

License

MIT, see LICENSE.md.