• Stars
    star
    1,334
  • Rank 35,232 (Top 0.7 %)
  • Language
    JavaScript
  • License
    BSD 2-Clause "Sim...
  • Created over 11 years ago
  • Updated over 2 years ago

Reviews

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

Repository Details

Stop your iOS webapp from bouncing around when scrolling

iNoBounce

Stop your iOS webapp from bouncing around when scrolling

The problem

You've built a nice full-screen mobile webapp, complete with scrollable elements using the -webkit-overflow-scrolling property. Everything is great, however, when you scroll to the top or bottom of your scrollable element, the window exhibits rubber band-like behavior, revealing a gray tweed pattern. Sometimes, your scrollable element doesn't scroll at all, but the window still insists on bouncing around.

The solution

No dependencies, no configuration, just include iNoBounce.

<script src="inobounce.js"></script>

Example

All you need is an element with height or max-height, overflow: auto and -webkit-overflow-scrolling: touch.

<script src="inobounce.js"></script>

<style>
    ul {
        height: 115px;
        border: 1px solid gray;
        overflow: auto;
        -webkit-overflow-scrolling: touch;
    }
</style>

<ul>
    <li>List Item 1</li>
    <li>List Item 2</li>
    <li>List Item 3</li>
    <li>List Item 4</li>
    <li>List Item 5</li>
    <li>List Item 6</li>
    <li>List Item 7</li>
    <li>List Item 8</li>
    <li>List Item 9</li>
    <li>List Item 10</li>
</ul>

See the examples/ folder for more examples, including a full-screen list, a canvas drawing app, and a fully skinned iOS-style app.

API

Loading inobounce.js will define the iNoBounce namespace. If the loading environment supports AMD, iNoBounce will register itself as a model and forgo defining the namespace.

  • iNoBounce.enable()
    Enable iNoBounce. It's enabled by default on platforms that support -webkit-overflow-scrolling, so you only need to call this method if you explicitly disable it or want to enable it on a platform that doesn't support -webkit-overflow-scrolling.

  • iNoBounce.disable()
    Disable iNoBounce.

  • iNoBounce.isEnabled()
    Returns a boolean indicating if iNoBounce is enabled.

  • iNoBounce.isScrollSupported
    A boolean value that indicates if the -webkit-overflow-scrolling css property is valid, effectively a browser detection flag.

Will it break my app that uses touch events like other solutions?

It shouldn't. iNoBounce includes an example of a canvas drawing app and has been used in conjunction with Hammer.js without affecting functionality.

How does it work?

iNoBounce detects if the browser supports -webkit-overflow-scrolling by checking for the property on a fresh CSSStyleDeclaration. If it does, iNoBounce will listen to touchmove and selectively preventDefault() on move events that don't occur on a child of an element with -webkit-overflow-scrolling: touch set. In addition, iNoBounce will preventDefault() when the user is attemping to scroll past the bounds of a scrollable element, preventing rubberbanding on the element itself (an unavoidable caveat).

Shoutouts

How can I get that awesome iOS CSS skin from the app example?

Check out iOCSS for a lightweight and easy to use iOS skin for your mobile webapp.

Tapping stuff has a delay, what the heck?

You need FastClick by FT Labs.

Now I want awesome multi-touch gestures too!

It's hammer time, baby. Check out Hammer.js from Eight Media.

License

iNoBounce is licensed under the permissive BSD license.

More Repositories

1

gulp-replace

A string replace plugin for gulp
JavaScript
496
star
2

mdn.io

The "I'm feeling lucky" URL shortener
JavaScript
215
star
3

gulp-handlebars

Handlebars plugin for gulp
JavaScript
171
star
4

gulp-karma

Karma plugin for gulp
JavaScript
75
star
5

gulp-csslint

CSSLint plugin for gulp
JavaScript
74
star
6

PseudoClass

An OOP framework for Node.js and the browser
JavaScript
66
star
7

DOMly

The fast template system that creates and clones DOM nodes
JavaScript
53
star
8

wellTested

A simple todo app tested with Karma, Jasmine, CasperJS, and Istanbul
JavaScript
45
star
9

scopedQuerySelectorShim

querySelector/querySelectorAll shims that enable the use of :scope
JavaScript
41
star
10

iOCSS

Simple, resolution independent, image-free CSS for mobile web applications
CSS
36
star
11

F

F, a Backbone component framework that encourages code re-use
JavaScript
23
star
12

Pinky

A straight-forward Promises/A+ 1.1 implementation
JavaScript
22
star
13

VoodooI2CGoodix

VoodooI2C satellite driver for Goodix touchscreens in C++
C++
20
star
14

gulp-declare

Safely declare namespaces and set their properties
JavaScript
17
star
15

quadtag

An Arduino-based laser tag system for quadcopters
Arduino
15
star
16

DuneBuggy

A 3D multiplayer dune buggy battle game written entirely in JavaScript
JavaScript
10
star
17

flexless

LESS mixins for the CSS Flexible Box Layout Module 2012 Editor's Draft with optional fallbacks for the 2009 W3C Working Draft.
9
star
18

karma-benchmark-reporter

A jsPerf-style reporter for karma-benchmark
JavaScript
5
star
19

TankGame

A 3D multiplayer tank battle game written entirely in JavaScript
JavaScript
5
star
20

nsdeclare

Safely declare a namespace using dot notation
JavaScript
5
star
21

stompinator

Elephant activity tracking (upstairs neighbor stomping) device for M5Stack Core2
C++
5
star
22

coronaglobe

Heatmap representation of COVID-19 on WebGl 3D world map
JavaScript
5
star
23

wolf4sdl-controller-mappings

A selection of controller mappings for wolf4sdl
4
star
24

fui

A flat UI library for the web
JavaScript
4
star
25

karma-benchmark-example

A karma-benchmark example
JavaScript
4
star
26

platformer

A platformer experiment
JavaScript
3
star
27

piControl

A client-server system for controlling the Raspberry Pi
JavaScript
3
star
28

gulp-karma-test

A repository dedicated to figuring out how to use Karma and gulp together without wanting to off one's self with a rusty spoon
JavaScript
3
star
29

coronadatascraper-cache

Cache for the coronadatascraper project
HTML
2
star
30

lazd.github.io

lazd's blog
HTML
2
star
31

shellcolor

ANSI colors for your Node.js app's stdout, stderror, and logs
JavaScript
2
star
32

commonesm

How to publish a module, maintain support for CommonJS, and test with jest
JavaScript
1
star
33

DOMly-cli

JavaScript
1
star
34

dilBot-rc

JavaScript
1
star
35

gulp-domly

DOMly plugin for gulp 3
JavaScript
1
star
36

coronavirus-data-sources

A list of coronavirus data sources by county
1
star
37

SimpleExpressServer

An express+Stylus server ala Python's SimpleHTTPServer
JavaScript
1
star
38

expressSeed

A Node.js + express app structure
1
star
39

grunt-domly

Grunt task to precompile DOMly templates
JavaScript
1
star
40

wolf4sdl

Wolf4SDL is an open-source port of id Software's classic first-person shooter Wolfenstein 3D to the cross-platform multimedia library SDL. It is meant to keep the original feel while taking advantage of some improvements.
C++
1
star