Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

All draggable elements effected if when manipulating them in onDown #8

Closed
peterssonanton opened this issue Jun 23, 2019 · 2 comments
Closed

Comments

@peterssonanton
Copy link

peterssonanton commented Jun 23, 2019

For example; If I try to change the opacity of an object when dragging it, I use onDown like this:

var test = new momentum.Draggable(first, {
			onDown:function(){  first.style.opacity = 0.5; },
			friction: 0.055
		});

However, that sets the opacity for all the draggable elements somehow. I made a jsFiddle to demonstrate: https://jsfiddle.net/y6ro8792/1/
Thanks for the great plugin!

@davideperozzi
Copy link
Owner

davideperozzi commented Jun 23, 2019

Hey, thanks for using the plugin! :)

I've updated your jsfiddle here: https://jsfiddle.net/davideperozzi/s0uhebdL/

The onDown callback is triggered if the container element gets hit, so in your case you need to check if the coordinates of the click event are inside the bounds of the element you want to modify the opacity.

You already get the prepared parameter hit as first argument. You should also return that in your onDown function in order to tell the handler the click was accepted by the element :)

var test = new momentum.Draggable(first, {
 onDown: function(hit) {  
   if (hit) {
     first.style.opacity = 0.5; 
   }

   return hit;
 },
 friction: 0.055
});

Let me know if that solves your problem :)

@peterssonanton
Copy link
Author

Ah! Thats perfect, thanks for the great support!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants