• Stars
    star
    254
  • Rank 160,264 (Top 4 %)
  • Language
    HTML
  • Created over 13 years ago
  • Updated over 3 years ago

Reviews

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

Repository Details

Custom events 'movestart', 'move' and 'moveend' for jQuery.

#jquery.event.move

Move events provide an easy way to set up press-move-release interactions on mouse and touch devices.

UPDATE 2.0: move events are now compatible with jQuery 3.x. In addition, the underlying implementation is rewritten using vanilla DOM (where before it was jQuery special events only) – jQuery is no longer a requirement. However, if you do not have jQuery you will require a polyfill for Object.assign to support older browsers. I can recommend Object.assign polyfill :)

##Demo and docs

stephband.info/jquery.event.move/

##Move events

movestart
Fired following mousedown or touchstart, when the pointer crosses a threshold distance from the position of the mousedown or touchstart.
<dt>move</dt>
<dd>Fired on every animation frame where a mousemove or touchmove has changed the cursor position.</dd>

<dt>moveend</dt>
<dd>Fired following mouseup or touchend, after the last move event, and in the case of touch events when the finger that started the move has been lifted.</dd>

Move event objects are augmented with the properties:

e.pageX
e.pageY
Current page coordinates of pointer.
e.startX
e.startY
Page coordinates the pointer had at movestart.
e.deltaX
e.deltaY
Distance the pointer has moved since movestart.
e.velocityX
e.velocityY
Velocity in pixels/ms, averaged over the last few events.

Usage

Use them in the same way as you bind to any other DOM event:

var node = document.querySelector('.mydiv');

// A movestart event must be bound and explicitly
// enabled or other move events will not fire
node.addEventListener('movestart', function(e) {
  e.enableMove();
});

node.addEventListener('move', function(e) {
  // move .mydiv horizontally
  this.style.left = (e.startX + e.distX) + 'px';
});

node.addEventListener('moveend', function() {
  // move is complete!
});

Or if you have jQuery in your project:

jQuery('.mydiv')
.on('move', function(e) {
  // move .mydiv horizontally
  jQuery(this).css({ left: e.startX + e.deltaX });

}).bind('moveend', function() {
  // move is complete!
});

(.enableMove() is a performance optimisation that avoids unnecessarily sending move when there are no listeners. jQuery's special event system does the work of enabling move events so using jQuery there is no need to explicitly bind to movestart.)

To see an example of what could be done with it, stephband.info/jquery.event.move/

##CommonJS

If you're using Browserify, or any other CommonJS-compatible module system, you can require this script by passing it your jQuery reference. For example,


require('./path/to/jquery.event.move.js')();

##Tweet me

If you use move events on something interesting, tweet me @stephband!

More Repositories

1

jparallax

jQuery plugin for creating interactive parallax effect
HTML
1,145
star
2

scribe

Renders music in HTML.
HTML
615
star
3

jquery.event.swipe

jQuery custom events swipeleft, swiperight, swipeup and swipedown
HTML
446
star
4

midi

Receive, transmit and manipulate browser MIDI events
JavaScript
54
star
5

jquery.transitions

Feature detects CSS transition support and provides two methods – .addTransitionClass() and .removeTransitionClass() – that manage transitions.
JavaScript
22
star
6

jquery.event.frame

Special event plugin providing exactly one timer to trigger 'frame' events on any number of objects.
JavaScript
21
star
7

jticker

jQuery plugin that prints elements like a ticker tape, whilst respecting the DOM tree that it tickers through
JavaScript
11
star
8

slide-show

A slideshow/carousel based on scroll snapping, implemented as the <slide-show> custom element.
HTML
11
star
9

dom

A library of functional DOM Functions and Event Streams for HTML and SVG in HTML
JavaScript
10
star
10

jquery.event.tap

jQuery tap event for more responsive touch interfaces.
JavaScript
8
star
11

jquery.choose.color

Colour chooser using Canvas to display a colour wheel. Includes opacity chooser.
JavaScript
6
star
12

bolt

class-based, evented front-end library
CSS
6
star
13

fn

A library of functional functions
JavaScript
5
star
14

music

A library of functions for analysing musical information.
JavaScript
5
star
15

sound.io

Repos for the sound.io project have been moved to
4
star
16

literal

Literal templates for the DOM
HTML
4
star
17

Color.js

Simple object for manipulating colours.
JavaScript
4
star
18

jquery.skin

A modular approach to creating user interface controls
JavaScript
4
star
19

jquery.event.scrollevents

A 'scrolltop' or 'scrollbottom' event that is triggered when the user hits the limits of a scroll.
JavaScript
3
star
20

midi-graph

A live graph of MIDI events as a browser component.
JavaScript
3
star
21

harmony-circle

An interactive cycle-of-fourths harmonic visualiser
JavaScript
3
star
22

sequencer.js

Sequencer for playback of timed event data, with a timer that compensates for latency, and realtime control of speed and offset.
JavaScript
3
star
23

colin

Colin does linear interpolation collision detection.
JavaScript
2
star
24

details-toggle

The `<details-toggle>` element.
HTML
2
star
25

guides

Adds a choice of toggle-able grid overlays to the page.
CSS
2
star
26

keys

1
star
27

midi-modules

A specification for making interoperable midi modules.
1
star
28

collection

An observable array-like object constructor.
JavaScript
1
star
29

vector

Vector() constructor
JavaScript
1
star
30

window

A static page that displays properties of the window object. Useful for quickly checking browsers.
HTML
1
star
31

stephband.github.com

CSS
1
star
32

midi-monitor

A live list display of MIDI events as a browser component.
JavaScript
1
star
33

midi-modify

A midi node for modifying messages
JavaScript
1
star
34

jquery.truncate

Text truncation for jQuery.
JavaScript
1
star
35

midi-filter

Filters MIDI events.
JavaScript
1
star
36

Audio.js

HTML5 patch to provide fallback for the Audio constructor
1
star
37

gameball

Arno and Elmars Game
HTML
1
star
38

marslander

JavaScript
1
star
39

midi-throttle

A MIDI node that throttles incoming messages to the browser's frame rate.
JavaScript
1
star
40

jquery.event.click

Special event plugin that extends the binding of 'click' events to support event delegation. An experimental alternative o using .live(). Requires jQuery 1.4.
JavaScript
1
star
41

form-elements

A collection of advanced custom elements for form controls
HTML
1
star