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

Overview

#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!

Comments
  • jQuery 3.0.0 breaks jQuery.event.props usage

    jQuery 3.0.0 breaks jQuery.event.props usage

    https://jquery.com/upgrade-guide/3.0/#breaking-change-jquery-event-props-and-jquery-event-fixhooks-removed

    jQuery's event handling performance increased thanks to a reorganization of event property management. The main improvement is that jQuery now only calculates or copies a property on the first access, rather than calculating and copying them up front. This is a really big win with properties that may force layout that the event handler may not even need. The most common use we know of was to add properties for pointer events, which is no longer necessary because those events are supported already in jQuery 3.0. The jQuery Migrate plugin provides support for these properties if you still need them. The related but undocumented mouseHooks and keyHooks lists were removed as well. The team is interested in understanding other use cases before defining new APIs, so feel free to open a ticket.

    opened by morganwdavis 8
  • Scrolling blocked on Chrome

    Scrolling blocked on Chrome

    I'm trying to use jquery.event.move.js v1.3.1 with Zurb Foundation's Clearing gallery, but when the plugin is in place, the scroll bar is inoperable in Chrome...

    opened by sampaccoud 6
  • Need 'movestart' on pointerdown

    Need 'movestart' on pointerdown

    I know it is a feature to not have the 'movestart' event fire until there is a move but I need that event raised before there is any move for my own purposes. Looked at the code and there is a threshold value set to 6 which I thought if I set it to 0 would do the job but no. I even removed the code in the checkThreshold() that short circuits the function but no luck.

    What do I need to do to get the movestart event immediately on pointer down? or maybe fix it so threshold = 0 behaves as expected.

    opened by Bortxx 5
  • Incoherent values for deltaY

    Incoherent values for deltaY

    Hi,

    after playing a little with your plugin, I found what seems a bug. Here is an output of some Chrome logging :

    This is just a copy of some consecutive move event properties.

    Object {delta: 0, y: 680, start: 686, dist: -6} 
    Object {delta: -1, y: 679, start: 686, dist: -7} 
    Object {delta: -1, y: 664, start: 686, dist: -22} 
    Object {delta: -7, y: 656, start: 686, dist: -30} 
    Object {delta: -7, y: 648, start: 686, dist: -38} 
    Object {delta: -6, y: 641, start: 686, dist: -45} 
    Object {delta: -1, y: 635, start: 686, dist: -51}
    

    deltaY is not coherent with other values. When I used it, animation was always slower than cursor movement. I switch my moving animation to distY and everything is ok.

    Thanks for your job !

    opened by antoinelouatron 5
  • Can´t use moveend on body and expect document scrolling to work on mobile devices.

    Can´t use moveend on body and expect document scrolling to work on mobile devices.

    On

    https://jsfiddle.net/twjou50r/1/embedded/result/

    I have a webpage where scrolling does not work very well on mobile devices. I am using the emulation in chrome to try this. A phone will also prove the issue.

    Problem: Nothing happends when I try to scroll, even if document content is taller than the window.

    If I remove the lines

    $('body').on('moveend', function ()
    {
        /* something */
    });
    

    scrolling works as demonstrated on: https://jsfiddle.net/twjou50r/2/embedded/result/

    (if you want to see the source of those jsfiddles, you click "Edit in JSFiddle")

    opened by AndersBillLinden 4
  • Mootools more conflict

    Mootools more conflict

    Hi. There is an issue when using your move event plugin in a page with Mootools more loaded. The following steps can reproduce the issue:

    1. Create an empty page with an element. Give position absolute to the element.
    2. Add mootools and mootools more to your page.
    3. Add jQuery and your move event plugin to the page.
    4. Just bind the 'move' event to the element using jQuery. The element will become draggable!

    Note that since you use the move plugin to the swipe plugin this issue also occurs in the swipe plugin.

    opened by kavadas 4
  • Plugin breaks in jQuery 1.8

    Plugin breaks in jQuery 1.8

    In jQuery 1.8 node.data('events') doesn't return events bound to the element anymore, it does $._data(node, 'events') instead. Because of this change plugin throws exception during execution. This also affects jQuery.event.swipe

    opened by can3p 4
  • Constrain to parent

    Constrain to parent

    Your plugin is exactly what i was looking for, It miss only a thing it's to constrain the drag to the parent div.

    And then it would be perfect for me.

    opened by onigetoc 3
  • currentTarget for delegated events

    currentTarget for delegated events

    Is there a way to get currentTarget to work correctly with delegated events or am I doing something wrong?

    $(".itemPalette").on "movestart", ".item", (e) ->
      $(e.currentTarget) # is document rather than .item
    
    opened by STRd6 3
  • touch device: page scrolling (in v 1.2)

    touch device: page scrolling (in v 1.2)

    Hey Stephen,

    If I view the demo page (v 1.2) on a touch device (I tried with an iPad, a galaxy nexus and a nexus 7) I can move the red thing around, but cannot scroll the page around anymore.

    I tried an older version (1.0.2) and the page scrolled normally.

    cheers JL

    opened by jlgeering 3
  • minification fails because of es6 features

    minification fails because of es6 features

    on line 101 char 12 you use for ... of ... which is es6 or with moz extension. I am prepending your js to mine then doing minification. since i am using jshint, jslint or eslint before minification it fails. I can tell my preprocessor to use es6 on your file only but it would be nice if you include it too. just add to the head of your script...

    /*jshint esversion: 6 */
    
    opened by bnomei 2
  • Vulnerability checks failing on js/jquery-3.1.1.js

    Vulnerability checks failing on js/jquery-3.1.1.js

    Within the project is an old version of jQuery in js/jquery-3.1.1.js

    Vulnerability checkers like retirejs indicate an issue with jquery.event.move, as it contains an outdated jQuery version with known vulnerabilities. As the readme of jquery.event.move notes jQuery is not required anymore, so removing (or updating) the jQuery would be appreciated.

    Thank you!

    opened by vssn 0
  • Can't scroll over input

    Can't scroll over input

    When the element to scroll contains an input element the user cannot scroll the container if they touch over the input element. For example:

    <div class="container" style="width: 500px; overflow: hidden;">
    <p>Hello World</p>
    <div style="width: 1100px">
    <input type="text" id="firstName" style="width: 200px; display: inline-block;" />
    <input type="text" id="firstName" style="width: 200px; display: inline-block;" />
    <input type="text" id="firstName" style="width: 200px; display: inline-block;" />
    <input type="text" id="firstName" style="width: 200px; display: inline-block;" />
    <input type="text" id="firstName" style="width: 200px; display: inline-block;" />
    </div>
    </div>
    

    In this case the user can scroll when they press over the paragraph but not when they press over the input.

    opened by harrington101 0
  • Versions 2.0.0+ broke vertical scroll in Edge Mobile

    Versions 2.0.0+ broke vertical scroll in Edge Mobile

    For some reason after updating from 1.3.6 to 2.0.1, vertical scroll has stopped working in the Microsoft Edge 14 browser in Windows 10 Mobile devices.

    Also, vertical scroll still works in the older Internet Explorer 11 mobile browser from an older Lumia, so this issue seems to affect Edge browsers only.

    Whenever the plugin is updated, kindly consider not using ECMA Script 2015 methods (like the Symbol function) to prevent developers from ditching this plugin or reverting to version 1.3.6 (like in my case). Users don't always have the device or the browser we would like them to have, so my recommendation is to avoid rendering the plugin unusable for older browsers because there's hardly anything in ES 2015 that is mandatory for the implementation of gestures.

    image

    opened by andreszs 0
  • Inner scroll won't work on iOS unless I remove preventDefault

    Inner scroll won't work on iOS unless I remove preventDefault

    I used your lib to add swipe-to-close interaction to hamburger menu. The menu has inner scroll. Just so you know, I needed to comment out one line in your code to enable inner scroll on iPhone devices.

    screen shot 2018-09-22 at 00 27 55

    It might be better not to prevent scrolling by default, but allow us to manually choose wether specific direction should prevent the default event.

    opened by maciejsaw 0
  • velocityX/Y is NaN

    velocityX/Y is NaN

    I was trying to use your other plugin "jquery.event.swipe.js" and find velocityX/Y return "NaN". Digging more, I come inside "jquery.event.move.js" and find when "updateEvent" is call, "timeStamp" is undefined and has side effect to false all calculation after about velocity. Digging again, I was trying to solve this adding "timeStamp" on "event" (inside "movestart" function) but browser throw a "TypeError: setting getter-only property "timeStamp" (which is not a surprise).

    In desperation, I corrected by setting a new parameter to "updateEvent" : function updateEvent(event, touch, timeStamp, eTimeStamp) { and for the call : updateEvent(event, data.touch, data.timeStamp, e.timeStamp);

    I'm sure this is not the best solution but at least it does the job ^^

    opened by Draeli 0
Owner
stephband
Front-end at @cruncher, musician.
stephband
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
Kuldeep 2 Jun 21, 2022
Smart Auto Move learns the size and position of your application windows and restores them to the correct place on subsequent launches. Supports GNOME Wayland.

smart-auto-move smart-auto-move is a Gnome Shell extension which keeps track of all application windows and restores them to the previous position, si

khimaros 40 Dec 23, 2022
Move all the disks from the left hand post to the right hand post, only moving the disks one at a time and a bigger disk can never be placed on a smaller disk.

Hanoi Tower Description The Tower of Hanoi was a famous problem posed by a mathematician in 1883, The "puzzle" is to move all the disks from the left

Dustin J Sellers 1 Feb 5, 2022
A dedicated desktop app that enables you to move items in and out of storage units in CSGO.

CASEMOVE Casemove is an open-source desktop application that helps you easily move items out of and into Storage Units in Counter-Strike: Global Offen

null 161 Dec 24, 2022
CSS classes to move your DOM!

CSShake Some CSS classes to move your DOM! Live Demo Download Center You could download the complete csshake.css file or separated files for each shak

Lionel Tzatzkin 4.7k Jan 4, 2023
Generated TypeScript interfaces for Aptos Move.

Aptos Framework TypeScript SDK Generated TypeScript interfaces for Aptos Move. This contains types for: AptosFramework MoveNursery MoveStdlib Releases

Aptosis 7 Aug 25, 2022
An enhanced VSCode extension for the Move programming language.

Move Analyzer Plus Provides language support for the Move programming language. Install on the VSCode Extension Marketplace: Move Analyzer Plus on the

The Moving Company 10 Aug 12, 2022
A to-do-list project is about keeping the track of all the daily task. This application can add move or delete task.

TO-DO LIST This is a project that create a simple todo tool that help you organize your day. This is build using ES6 and webpack. Built With HTML CSS

suzana marsela 8 Oct 26, 2022
js move playground by imcoding.online

JS MOVE PLAYGROUND Wrapper move playground by pontem. Only support Browser environment. Demo imcoding.online Install npm i @imcoding.online/js-move-pl

imcoding.online 14 Dec 3, 2022
A Chess learning tool where you have to find a top-engine move in a random position.

Just A Chess Move A Chess learning tool where you have to find a top-5 move in a random position. There aren't necessarily any tactics, you have to ju

Daan Heskes 14 Sep 18, 2022
ALU Map is a web-based platform that will help students move around ALU Rwanda Campus.

ALU-MAP ALU Map is a web-based platform that will help students move around ALU Rwanda Campus. Introduction Please refer to CONTRIBUTING.md for contri

null 5 Oct 25, 2022
jQuery based scrolling Bar, for PC and Smartphones (touch events). It is modern slim, easy to integrate, easy to use. Tested on Firefox/Chrome/Maxthon/iPhone/Android. Very light <7ko min.js and <1Ko min.css.

Nice-Scrollbar Responsive jQuery based scrolling Bar, for PC and Smartphones (touch events). It is modern slim, easy to integrate, easy to use. Tested

Renan LAVAREC 2 Jan 18, 2022
adds the *scrollin* and *scrollout* events to jquery, which will fire when any given element becomes (respectively) visible and invisible in the browser viewpori

jQuery.scrolling This plugin adds the scrollin and scrollout events to jquery: these events will fire when any given element becomes visible/invisible

Dark 5 Apr 7, 2021
A jQuery plugin that lets you attach callbacks to useful image loading events.

waitForImages Copyright (c) 2011-2018 Alexander Dickson @alexdickson Licensed under the MIT licenses. http://alexanderdickson.com Donate! Overview Pro

Alexander Dickson 1.3k Dec 28, 2022
logseq custom.js and custom.css utilities : resize query table columns, hide namespaces...

logseq-custom-files custom.js and custom.css utilities for Logseq. current version v20220331 query table view : add handles on the query table headers

null 44 Dec 7, 2022
Ready to manipulate partitions file? Create a custom partition, apply custom security system, hide the partition and share your hidden data on the www

Paranoia ?? Ready to manipulate partitions file? Create a custom partition, apply custom security system, hide the partition and share your hidden dat

Alice Snow 3 Dec 29, 2022