• Stars
    star
    310
  • Rank 134,926 (Top 3 %)
  • Language
    JavaScript
  • Created over 13 years ago
  • Updated over 7 years ago

Reviews

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

Repository Details

A simple, standalone library to invoke the tap event for touch-friendly web browsers.

Tappable

Tappable is a simple, standalone library to invoke the tap event for touch-friendly web browsers. Currently it's only tested on iOS Mobile Safari as I don't have any other smartphones to test with. The codebase is heavily inspired by Matteo Spinelli's Remove onClick delay on webkit for iPhone and Ryan Fioravanti's Creating Fast Buttons for Mobile Web Applications.

Here's how you implement the code:

tappable('#selector', function(){
	alert('tap');
});

Simple.

Why 'tap'?

First, it would be wise to read the articles linked above to understand the purpose of this script. But if you're lazy, take a look at this diagram:

Diagram 1

So, that's the tap event. But wait the minute, I can just use the touchend event to simulate a tap, right? Wrong, because:

Diagram 2

This means that once the finger moves, it will not fire the tap event. However, Tappable works in two special cases. First is the normal case:

Diagram 3

When the page scrolls, the button is not tapped.

The second case is the noScroll mode, where moving your finger on the element will not make the page scroll. This is useful for mobile web apps which might implement their own fixed headers or sections on the page.

Diagram 4

The button is tapped when the finger is on top of the button, even after moving in and out.

Documentation

Syntax

tappable(selector, opts);

Arguments

  1. selector - (string) The CSS selector expression of element to be tapped.
  2. opts - The options object or a function.
    • (object) The options to be passed.
    • (function) The function to execute when tapped.

Options

  • noScroll - (boolean: defaults to false) Whether or not to scroll when moving on the element.
  • activeClass - (string: defaults to tappable-active) A string indicating the active class applied to the element.
  • onTap - (function) The function to execute when tapped.
  • onStart - (function) The function to execute when touchstart event is fired.
  • onMove - (function) The function to execute when touchmove event is fired.
  • onMoveOut - (function) The function to execute when touch moves out of the element, if noScroll is true.
  • onMoveIn - (function) The function to execute when touch moves back in the element, if noScroll is true.
  • onEnd - (function) The function to execute when touchend event is fired.
  • onCancel - (function) The function to execute when touchcancel event is fired, or when touch moves if noScroll is false.
  • allowClick - (boolean: defaults to false) Whether or not to preventDefault the click on the element.
  • boundMargin - (integer: defaults to 50) A number indicating the bounding area of tapped region (of the element).
  • noScrollDelay - (integer: defaults to 0) A number indicating the delay in ms before 'noScroll' option kicks in.
  • activeClassDelay - (integer: defaults to 0) A number indicating the delay in ms before the active class is applied.
  • inactiveClassDelay - (integer: defaults to 0) A number indicating the delay in ms before the active class is removed.

Instance Object

  • el - (object) A reference to the bound DOM element.
  • destroy - (function) Removes event listeners from the bound DOM element.

Demo

Load http://fiddle.jshell.net/cheeaun/jxwsy/show/light/ in your browser. Edit here http://jsfiddle.net/cheeaun/jxwsy/. Or scan this QR code:

http://fiddle.jshell.net/cheeaun/jxwsy/show/light/

Event Delegation (for tagged version 0.1)

Note: This is no longer needed. The latest code now does event delegation by default.

Here's a simple example:

tappable(document.body || document.getElementsByTagName('body')[0], {
	onTap: function(e, target){
		// e.target works too
		if (target.tagName.toLowerCase() == 'a'){
			alert('tap');
		}
	}
});

For (almost) every callback function, a second argument which is the target element node, is passed. As a bonus, the event object also have an additional target attribute which is the target node (can be any node type, not just element node).

Contributing

Feel free to fork this project! Help and feedback would be appreciated, especially if this could be tested on Android, WebOS or any other touch-friendly browsers, not just mobile ones.

License

Tappable is licensed under the MIT license.

More Repositories

1

life

Life - a timeline of important events in my life
HTML
2,715
star
2

hackerweb

A simply readable Hacker News web app
CSS
1,210
star
3

phanpy

A minimalistic opinionated Mastodon web client
JavaScript
1,070
star
4

mooeditable

[DISCONTINUED] A simple web-based WYSIWYG editor, written in MooTools.
JavaScript
1,047
star
5

awesome-hacker-news

Awesome Hacker News: a collection of awesome Hacker News apps, libraries, resources and shiny things.
887
star
6

javascript-error-logging

A collection of JavaScript error logging services, resources and shiny things.
551
star
7

puppetron

Puppeteer (Headless Chrome Node API)-based rendering solution.
JavaScript
527
star
8

repokemon

Showcase of GitHub repos with PokΓ©mon names
CSS
338
star
9

node-hnapi

Unofficial Hacker News API
JavaScript
332
star
10

busrouter-sg

BusRouter SG: Singapore Bus Routes Explorer
JavaScript
302
star
11

hackerweb-native

A simply readable Hacker News app for iOS & Android, built with React Native. V2 now over here https://github.com/cheeaun/hackerweb-native-2
JavaScript
184
star
12

exploretrees-sg

🌳 Explore Trees in Singapore πŸ‡ΈπŸ‡¬
JavaScript
133
star
13

earth

🌏 A map of places I've checked in on Earth.
JavaScript
121
star
14

neat-bookmarks

A neat bookmarks tree popup extension for Chrome [DISCONTINUED]
JavaScript
106
star
15

arrivelah

Fast simple API for bus arrival times in Singapore.
JavaScript
90
star
16

chengyu-wordle

Wordle, for Chinese idioms - 成语 (chΓ©ngyΗ”)
JavaScript
85
star
17

kyoku

A tiny app that shows iTunes current playing song on Mac menu bar
JavaScript
85
star
18

3d-earth

🌏🌎🌍 3D Earth with Mapbox GL, D3.js and Three.js
HTML
76
star
19

steepless

An app to find the flattest routes and avoid the hilliest routes
JavaScript
69
star
20

3d-touch-canvas

3D Touch Canvas, for iPhone 6S, 6S Plus and iPad Pro
HTML
62
star
21

hackerweb-native-2

HackerWeb 2: A read-only Hacker News client.
JavaScript
59
star
22

jquery.livefilter

Slightly advanced live filtering jQuery plugin
JavaScript
54
star
23

react-native-cache-store

A localStorage-like wrapper around React Native's AsyncStorage with cache expiration.
JavaScript
45
star
24

railrouter-sg

A progressive web app that lets you explore MRT and LRT rail routes in Singapore
JavaScript
43
star
25

photorealistic-3d-deckgl

Deck.GL with Google Maps Photorealistic 3D Tiles demo - lighting with shadows and post-processing effects
HTML
39
star
26

checkweather-sg

β˜€οΈπŸŒ§ Yet another weather app for Singapore
JavaScript
39
star
27

sgbusdata

Singapore Bus data
JavaScript
36
star
28

kanade

A Mobile web app to list anime series for every season, with scores and stuff for easy comparison.
JavaScript
31
star
29

taxirouter-sg

A web app that lets you explore available taxis and taxi stands in Singapore
JavaScript
30
star
30

moodoco

HTML5 Offline Documentation for MooTools Core and More.
25
star
31

mooj

jQuery-like syntax for Mootools.
JavaScript
25
star
32

sgraildata

Singapore Rail data
JavaScript
20
star
33

octofication

A nifty little Chrome extension for displaying GitHub notifications.
JavaScript
17
star
34

rain-geojson-sg

Straight-forward API server to convert rain area radar images (Singapore) to GeoJSON
JavaScript
16
star
35

getSelector.js

Get the shortest possible CSS selector path of an element.
JavaScript
14
star
36

tweet2md

Convert a tweet to Markdown
HTML
12
star
37

aimp-mobile-web-ctl

AIMP Mobile Web Control interface.
JavaScript
11
star
38

npm-star

Star GitHub repositories of your project's npm dependencies
JavaScript
11
star
39

om3d

Demo of Singapore buildings 3D tiles from OneMap on Mapbox GL JS.
JavaScript
11
star
40

pinpoint

Pinpoint is a Chrome extension that allows you to link to any part of a page.
JavaScript
11
star
41

whathappen-sg

What's Happening in Singapore
HTML
10
star
42

phoenity-icons

Simple icons for everyone.
10
star
43

connectionsmy

Tech things aggregator for Malaysia
HTML
10
star
44

sgtreesdata

Singapore Trees data
JavaScript
10
star
45

macos-quick-actions

A list of macOS Quick Actions / Services that I use on my machine
9
star
46

cheeaun.github.com

cheeaungit
9
star
47

hackerwebapp.com

HackerWeb
HTML
9
star
48

tweets

An off-site archive of tweets from Twitter
JavaScript
9
star
49

cacss

CSS in its simplest form.
JavaScript
9
star
50

chidori

A simple Twitter client, created with Titanium.
8
star
51

max-tabs

A no-restart Firefox extension to set maximum number of opened tabs in a window.
JavaScript
8
star
52

tweet-couch

Archive your tweets in a relaxing way.
JavaScript
8
star
53

cheeaun.com

cheeaun's web site
HTML
8
star
54

nobita

πŸ“œπŸ“ Script to check in to a Foursquare (Swarm) location when user is within range. Uses CoreLocation. Only for macOS.
JavaScript
7
star
55

streetview-fun

Having fun with Google Maps StreetView API
JavaScript
7
star
56

kopi.guide

A helpful guide on how to order Kopi in Singapore and some say Malaysia too.
HTML
7
star
57

img-alt-api

Simple API endpoint for image alt description generation, powered by OpenAI GPT-4 with Vision
JavaScript
7
star
58

example-fx

An example Firefox extension for anyone to fork.
JavaScript
6
star
59

psi-sg

A web app that displays PSI readings in Singapore
HTML
6
star
60

gh-starred-repos-feed

A Cloudflare Worker that returns the starred repos of a GitHub user as a RSS feed
JavaScript
6
star
61

mapwalker

JavaScript
6
star
62

mangafeeder

Latest manga chapters from Mangareader.net, available in JSON and RSS formats.
JavaScript
6
star
63

checkweather-sg-native

β˜€οΈπŸŒ§ Yet another weather app for Singapore
JavaScript
6
star
64

moohub

GitHub API wrapper, in MooTools.
JavaScript
5
star
65

bgcolorful

A simple page for showing how browsers render the color value of 'bgcolor' attribute
5
star
66

ndp2020-wishes

Map and word cloud of wishes made during National Day Parade 2020 in Singapore
JavaScript
5
star
67

ca-generator

A web-based cheeaun logo generator, with configurable shapes, colors and dimensions.
HTML
5
star
68

slakoth

A Slack bot that auto-post daily tech events in Singapore
JavaScript
5
star
69

iosconfsg-2017-design

Design files for iOSConf SG 2017
OpenSCAD
5
star
70

twitter-clients-chart

Twitter clients distribution in real-time, based on the work by Dan Zajdband, twitter-clients.herokuapp.com
5
star
71

alba-ewaste-sg-dropoff-locations

ALBA E-Waste Drop-off Locations
TypeScript
5
star
72

sgnightfest

SG Night Fest Map
JavaScript
5
star
73

branding

Branding for myself
5
star
74

the-sexy-curls-jquery-plugin

A page-turning plugin for jQuery
JavaScript
5
star
75

pagezoom

A MooTools class to zoom in anything in a page
JavaScript
4
star
76

f1sg

A 2.5D map of the Singapore F1 Grand Prix circuit with landmarks around
HTML
4
star
77

jquery.tabscrollify

scrollify your tabs, baby
JavaScript
4
star
78

pentagoo

The popular Pentago game by MindTwister, written in Javascript.
PHP
4
star
79

toransureto

Any Language β†’ Japanese β†’ Romaji translation service, powered by Google App Engine
Python
4
star
80

rainshot

A serverless puppeteer instance to capture rain radar image of Singapore.
HTML
4
star
81

shuffletext.js

shuffleText.js - Class for creating text shuffling effects
JavaScript
4
star
82

gh-proxy

Cloudflare Worker ⚑ gh-proxy - Set up a (sub)-domain proxy for Github Pages.
JavaScript
4
star
83

lingva-api

Simple API endpoint based on Lingva Translate
JavaScript
4
star
84

nakeddayjs

nakedDay.js for the CSS Naked Day.
3
star
85

venusaur

iCal as a Service
3
star
86

urly

URL shortener for Google App Engine
Python
3
star
87

malaysia-flag-css

Pure CSS Malaysia Flag
3
star
88

jquery.spacetagging

slight feature rip-off of HeadSpace2 http://urbangiraffe.com/plugins/headspace2/
JavaScript
3
star
89

barcampkl-hub

The Hub, for KL BarCampers.
JavaScript
3
star
90

Fx.TransMorph

Just like Fx.Morph, but allows per-property transitions.
JavaScript
3
star
91

bubble-wrap

A rather satisfying bubble wrap popping game.
JavaScript
3
star
92

sg3rdata

Singapore 3R data
TypeScript
3
star
93

sg-rain-radar-scribbler

An experimental web app to load rain radar images from weather.gov.sg and allow scribbling of the images at 5-minute intervals while generating a JSON output of the radar with a "Download" button.
HTML
3
star
94

talks

My talks
HTML
3
star
95

moneygowhere

JavaScript
3
star
96

pentagoo-wave

Pentagoo on Wave
3
star
97

mootools-search-chrome

Chrome extension to search MooTools' blogs, demos, documentation, forums and tutorials
2
star
98

hnmobile

Hacker News web app [MOVED]
2
star
99

cheeaun

My special repository
2
star
100

.github

Global .github
2
star