briangonzalez / jquery.pep.js

👟 Pep, a lightweight plugin for kinetic drag on mobile/desktop
http://pep.briangonzalez.org
1.3k stars 178 forks source link

Don't count "click" as "drag" #144

Closed BlaM closed 9 years ago

BlaM commented 9 years ago

Not sure if I'm missing something.

I use pep for drag and drop with draggable elements and droppable areas. Each draggable element also starts on an droppable area, but usually I don't want the element to be dropped on the area where it started.

Right now a "click" on one of the draggable elements seems to count as "drag" - the stop function is called.

I thought I could avoid this by setting startThreshold to the size of the element, so it has to be moved out of the drop area first - but that does not seem to change anything.

Is there an option to make "drag" only count of the user actually kept the element under control for some time and not just clicked on it?

Joeao commented 9 years ago

Hi BlaM, Check the following option:

callIfNotStarted:               ['stop', 'rest']

This shows which events are called if a click occurs and a movement isn't made. Remove stop from this array in order for stop to not be called on a click without a drag.

An alternate method would be to have your stop event function look something like this:

stop: function(e, obj) {
    if(obj.started) {
        DoSomething()
    }
}

I'd then recommend using startThreshold, as you mentioned, to control the users click length, rather than timing it. However if you did want to start after X milliseconds, you could do something like:

drag: function(e, obj) {
    obj.started = false;

    setTimeout(function() {
        obj.started = true;
    }, 200) // Replace 200 with desired milliseconds
}

Then use the previously mentioned alternate method. Though I wouldn't recommend this.

Hope that helps!

briangonzalez commented 9 years ago

thanks @Joeao!