• Stars
    star
    212
  • Rank 186,122 (Top 4 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 11 years ago
  • Updated almost 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

[DEPRECATED: You should use https://github.com/pazguille/decouple] Decouple the scroll event from the callback functions.

scrolling

Decouple the scroll event from the callback functions using requestAnimationFrames.

Itโ€™s a very, very, bad idea to attach handlers to the window scroll event.

Depending upon the browser the scroll event can fire a lot and putting code in the scroll callback will slow down any attempts to scroll the page (not a good idea). Any performance degradation in the scroll handler(s) as a result will only compound the performance of scrolling overall. Instead itโ€™s much better to use some form of a timer to check every X milliseconds OR to attach a scroll event and only run your code after a delay (or even after a given number of executions โ€“ and then a delay).

by John Resig.

Based on

Installation

$ npm install scrolling

$ bower install scrolling

$ component install pazguille/scrolling

Usage

First, requires the scrolling component:

var scrolling = require('scrolling');

Now, define a listener for any HTMLElement:

function foo(event) {
    console.log('foo');

    // The function receive the scroll event as parameter.
    console.log(event);

    // The function context is the scrolled element.
    console.log(this.scrollTop);
}

function bar() {
    console.log('bar');
}

Then, add some HTMLelements and its listeners to scrolling:

scrolling(document.querySelector('#box'), foo);
scrolling(window, bar);

// or

scrolling(bar);

API

scrolling(el, listener)

Adds an el with a listener to the collection.

  • el [optional] - A given HTMLElement to add to scroll.
  • listener - A given listener to execute when the given el is scrolled.
scrolling(el, listener);

scrolling#remove(el, listener)

Removes an el or its listener from the collection with the given el.

  • el - A given HTMLElement to remove.
  • listener [optional] - A given listener to remove.
scrolling.remove(el, listener);

// or

scrolling.remove(el);

Build

npm run dist

Test

Open file ./test/test.html in your browser.

Made with โค by

License

MIT license. Copyright ยฉ 2014.

More Repositories

1

offline-first

๐Ÿ”Œ Everything you need to know to create offline-first web apps.
2,986
star
2

github-card

:octocat: A web component to show a card for your GitHub profile
HTML
652
star
3

voix

๐Ÿ“ข A JavaScript library to add voice commands to your sites, apps or games.
JavaScript
551
star
4

viewport

๐Ÿ’ป Gets the dimensions of the Viewport and beyond.
JavaScript
536
star
5

aload

Loads images, background images, scripts, styles, iframes, videos and audios asynchronously (just 241 bytes).
JavaScript
410
star
6

flipload

Flipping elements and show a loading indicator easily.
JavaScript
291
star
7

horwheel

Scroll horizontally with mouse wheel.
HTML
178
star
8

shuffle-array

Randomize the order of the elements in a given array for the browser and node.js.
JavaScript
167
star
9

daturi

Converts images to Base64.
JavaScript
146
star
10

is-near

Calculates if the mouse position is near to a given element.
JavaScript
134
star
11

sticky

Stick elements to the top of the viewport when the user scrolls down.
JavaScript
88
star
12

demo-battery-api

๐Ÿ”‹ Battery Status API Demo
CSS
65
star
13

clicktap

A JavaScript library to prevent the 300ms click delay on touch devices (just 736 bytes).
JavaScript
56
star
14

decouple

Decouple the DOM events from expensive functions.
JavaScript
51
star
15

jvent

An universal JavaScript Emitter based on NodeJS EventEmitter.
JavaScript
46
star
16

musique

๐ŸŽต A JavaScript Music Player API to create custom players.
JavaScript
34
star
17

path

Simple routing library using HTML5 history.pushState or hashbang for web browsers.
JavaScript
33
star
18

async-img

[DEPRECATED: You should use https://github.com/pazguille/aload] Asynchronous Image Loader.
JavaScript
27
star
19

upfile

Makes file inputs a pleasure to use with progressive enhancement.
JavaScript
24
star
20

selfstorage

Library for caching JavaScript resources in the localStorage.
JavaScript
18
star
21

checked

โœ… UI components using :checked CSS pseudo-class selectors.
CSS
16
star
22

CORS

Simple and tiny CORS component
JavaScript
16
star
23

camera-action

๐Ÿ“ท Camera-action is a component to ease camera (getusermedia) management.
JavaScript
15
star
24

emitter-es6

A JavaScript Emitter written in ES6.
JavaScript
14
star
25

web-vitals-leaderboard

The simplest way to understand how your siteโ€™s user experience compares to other major sites in your industry.
JavaScript
13
star
26

euclidean

Calculates the distance between two points.
JavaScript
13
star
27

gloomy

A simple and semantic substitution template engine for the browser :[
JavaScript
12
star
28

mediumjs

A small library that implements the Mediator Pattern in JavaScript.
JavaScript
11
star
29

route66

Simple routing library using hashbang for web browsers.
JavaScript
11
star
30

collected-notes-extension

A Chrome extension to create new notes with just one click (alpha)
JavaScript
11
star
31

BAMeetups

Listado de grupos/eventos/conferencias (meetups) nerds que se realizan en Buenos Aires. [WIP]
11
star
32

editable-plugin

Simple and tiny in-place Editor
JavaScript
10
star
33

ask

โ” A JavaScript library to ask basic questions.
JavaScript
10
star
34

editable

โœ๏ธ Simple and tiny in-place Editor component
JavaScript
9
star
35

xbox-games-api

JavaScript
8
star
36

haysubte

๐ŸšŠ Web App para ver el Estado del Subte
JavaScript
7
star
37

feriados

Web App para ver los feriados nacionales de Argentina, Chile y Uruguay.
HTML
7
star
38

oops.js

Oops! JS is an Object Oriented JavaScript Library
JavaScript
7
star
39

scrollshit

๐Ÿ’ฉ A JavaScript library to hijacking the userโ€™s scroll
HTML
6
star
40

jquery.cors

Simple and tiny CORS jQuery Plugin (only 0.447 kb)
JavaScript
6
star
41

web-vitals-api

Given a set of urls returns its core web vitals metrics.
JavaScript
5
star
42

xstoregames-app

XStore: La tienda de Xbox Argentina con impuestos incluidos
JavaScript
5
star
43

chico.bootstrap

A Chico UI flavor based on Twitter Bootstrap
4
star
44

bus

๐ŸšŒ A JavaScript Event Bus written in ES6.
JavaScript
4
star
45

third-party-widget

An example of third-party widgets from React components
JavaScript
4
star
46

website

My personal website.
HTML
3
star
47

saw.js

Simple Ajax for Web Workers
JavaScript
3
star
48

islandy

๐Ÿ๏ธ islandy: Islands meet Express.js & Preact
JavaScript
3
star
49

blog

My personal blog using Deno ๐ŸŒง๐Ÿฆ•
JavaScript
3
star
50

resume

My Professional Resume.
HTML
3
star
51

SUBE.me

Where can I charge my SUBE card?
JavaScript
3
star
52

xbox-precios-extension

JavaScript
2
star
53

sal.js

Simple Ajax Library
JavaScript
2
star
54

teno

Teno: A markdown-based note-taking web app with Deno ๐Ÿ“ ๐Ÿฆ•
JavaScript
2
star
55

fonts-fouc

@font-face without FOUC
CSS
2
star
56

hotkeys.js

A simple library for add/remove hotkeys to DOM.
JavaScript
2
star
57

oscillator

An oscillator instrument that anyone can play with touch control system.
JavaScript
2
star
58

playground

Javascript + HTML5 + CSS3 Playground
JavaScript
2
star
59

webcomponents

Getting started with Web Components
2
star
60

stale-lru-cache-cluster

A promise-based Stale LRU Cache with support for cluster.
JavaScript
2
star
61

pip

A bookmarklet to enable PIP (Picture-in-Picture) feature on any video content.
HTML
1
star
62

xstore-nextjs

JavaScript
1
star
63

pazguille

Itโ€™s a me, Guille!
1
star
64

xstore-fresh

XStore: La tienda argenta de Xbox con precios finales + impuestos en ๐Ÿ‹ Fresh
JavaScript
1
star
65

gamepads

[WIP] ๐ŸŽฎ Gamepad API wrapper for Web Browsers.
JavaScript
1
star
66

camera-action.streaming

JavaScript
1
star
67

md.js

JavaScript Motion Detection
JavaScript
1
star
68

cutra

My first app using Sinatra to cut urls.
CSS
1
star
69

eachother

๐Ÿ‘ซ Super tiny data binding JavaScript library for modern browsers.
1
star
70

isomorphic-test

An isomorphic JavaScript test.
JavaScript
1
star
71

hot.on.pinterest

[Deprecated] - What's hot on Pinterest - Unofficial chrome extension to view the most popular pins.
JavaScript
1
star
72

import-wc

Import Web Components using Web Components
HTML
1
star
73

islandy-movies

Movie DB App built with Islandy
JavaScript
1
star
74

ps-games-api

JavaScript
1
star
75

basestyle

A development kit that provides the most basic styles for your responsives sites.
1
star
76

pstoregames-app

PStore: La tienda argenta de PlayStation con precios finales + impuestos
JavaScript
1
star
77

sw

Demo of how to use Service Workers to assets (js, css, fonts, imgs)
JavaScript
1
star
78

vitals-leaderboard-redirect

HTML
1
star
79

preact-islands-express-demo

๐Ÿ๏ธ Preact Islands with Express.js
JavaScript
1
star
80

islandy-demo

JavaScript
1
star
81

static-blog-nextjs

TypeScript
1
star
82

xstore-sveltekit

JavaScript
1
star
83

dont-make-me-wait

Examples, videos and slides.
CSS
1
star
84

tindercats

๐Ÿ˜ป Any cat can change your life
HTML
1
star
85

hotgram

Hotgram - Unofficial chrome extension to view the most popular photos on instagram.
JavaScript
1
star
86

prismatic

Unofficial chrome extension to discover and read social news on Prismatic
JavaScript
1
star
87

tastishes

Discover and share the tastiest dishes
JavaScript
1
star
88

getting-started-with-ruby

Getting started with Ruby.
Ruby
1
star