• Stars
    star
    255
  • Rank 153,977 (Top 4 %)
  • Language
    HTML
  • Created about 13 years ago
  • Updated almost 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

jquery.event.swipe

jQuery custom events swipeleft, swiperight, swipeup and swipedown
HTML
447
star
3

scribe

Music notator. Takes JSON, outputs SVG.
HTML
66
star
4

midi

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

jquery.transitions

Feature detects CSS transition support and provides two methods – .addTransitionClass() and .removeTransitionClass() – that manage transitions.
JavaScript
23
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

dom

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

jquery.event.tap

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

slide-show

A slideshow/carousel based on scroll snapping, implemented as the <slide-show> custom element.
HTML
7
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

music

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

fn

A library of functional functions
JavaScript
4
star
15

sound.io

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

jquery.skin

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

literal

Literal templates for the DOM
JavaScript
4
star
18

Color.js

Simple object for manipulating colours.
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

guides

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

keys

1
star
25

midi-modules

A specification for making interoperable midi modules.
1
star
26

collection

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

vector

Vector() constructor
JavaScript
1
star
28

colin

Colin does linear interpolation collision detection.
JavaScript
1
star
29

window

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

midi-modify

A midi node for modifying messages
JavaScript
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

Audio.js

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

jquery.truncate

Text truncation for jQuery.
JavaScript
1
star
35

midi-filter

Filters MIDI events.
JavaScript
1
star
36

marslander

JavaScript
1
star
37

gameball

Arno and Elmars Game
HTML
1
star
38

midi-throttle

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

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