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

jquery-sweet-scroll

v1.0.0

Published

It is possible to easily and flexibly implement smooth scrolling in the same page.

Downloads

4

Readme

jquey-sweet-scroll

NPM

It is possible to easily and flexibly implement smooth scrolling in the same page.

Demo

screenshot

demo

Requirements

jQuery 1.7.2 + or Zepto 1.1.x +

Install

npm

$ npm install jquery-sweet-scroll

Bower

$ bower install jquery-sweet-scroll

Manual

<script src="jquery.sweet-scroll.min.js"></script>

Usage

It is very simple.

HTML

<a href="#header">To #header</a>

JavaScript

// Start by clicking the anchor that begins with "#"
$("a[href^='#']").sweetScroll();

Options

duration

type: integer | "auto"
default: 1200
Specifies the scroll animation speed.

delay

type: integer
default: 0
Specifies the milliseconds to start to scroll.

easing

type: string
default: "easeOutQuint"
Specifies the easing function of scroll.
The following can be used by default.

jQuery:

  • "linear"
  • "swing"
  • "easeInQuint"
  • "easeOutQuint"
  • "easeInOutQuint"

To use the other easing functions to install such as jQuery.easing.js.

Zepto:

  • "linear"
  • "ease-in"
  • "ease-out"
  • "ease-in-out"

target

type: string
default: null
Specifies the target of the scroll position.

Example:

$(selector).sweetScroll({
  target: "#header"
});

to

type: mixed
default: null
Specifies the scroll positions. various specification format of href and to and offset option.

// Object format
{top:100, left:400}
{top:1000}

// Like the object format
"top:100, left:400"
"top:1000"

// Array format
[500, 0]

// Like the array format
"500,1000"

// Numeric format
500

offset

type: mixed
default: null
Adjust the scroll positions.
Please specify format Check the to option.

autoCoefficient

type: integer
default: 2
Coefficient for "auto" speed.

stopScroll

type: boolean
default: true
Stop scrolling in any of the events of the wheel or touch start(move).

changeHash

type: boolean
default: false
Change the hash after scrolled.

verticalScroll

type: boolean
default: true
Enable the vertical scroll.

horizontalScroll

type: boolean
default: false
Enable the horizontal scroll.

loadedScroll

type: boolean
default: false
Scroll to the position of the hash when the page read.

loadedScrollQuery

type: boolean
default: false
Scroll to the position of the query string when the page read.
The priority than the loadedScroll option.

stopPropagation

type: boolean
default: true
Stop the bubbling of anchor click event.

useVelocity

type: boolean
default: true
if velocity is possible to use from the jQuery or Zepto is used as an alternative to animate() method.

beforeScroll

type: function
default: null
param: object
function to be called before scrolling occurs.
The argument contains the property to be used for the animation.
In addition, you can interrupt the operation by returning false to this function.

afterScroll

type: function
default: null
param: object function to be called after scroll animation occurs. The argument contains the property to be used for the animation.

cancelScroll

type: function
default: null
function to be called the scroll is canceled.

Custom Event

Original event with the same name as the callback you can use.

Example:

$("a[href^='#']")
  .sweetScroll() //Run the SweetScroll
  .on("sweetscroll.beforeScroll", function(e){
    // ...
  })
  .on("sweetscroll.afterScroll", function(e){
    // ...
  })
  .on("sweetscroll.cancelScroll", function(e){
    // ...
  });

Methods

Local

// Disable SweetScroll.
$(selector).sweetScroll("disable");

// Enable SweetScroll.
$(selector).sweetScroll("enable");

// Disable SweetScroll.
$(selector).sweetScroll("destroy");

Public

// Specify the operation at the time of page load.
// You need to run before the DOMContentLoaded event.
$.sweetScroll("loaded", {
  // parametors.
});

// Global Disable SweetScroll.
$.sweetScroll("disable");

// Global Enable SweetScroll.
$.sweetScroll("enable");

// Global Destroy SweetScroll.
$.sweetScroll("destroy");

Browser Support

Using jQuery

  • Internet Explorer 7 +
  • Chrome
  • Safari
  • Firefox
  • iOS 5 +
  • Android 2.3

Using Zepto

  • Internet Explorer 9 +
  • Chrome
  • Safari
  • Firefox
  • iOS 5 +
  • Android 2.3

Licence

Released under the MIT Licence

Author

tsuyoshi wada