0

I'm using Jquery "draggagle" & "droppable".
When i drop an draggable element on another draggable element i'd like to change the background-color of the element in the bottom. (Not the dropzone)

Some kind of "mouseover", but "elementover" :)

What have i tried?
Barely nothing, i'm trying to figure out what syntax to use.
There is a "over" function for "droppable" but it only works on "dropzones".
Jquery has a "hover.()" function, but it works for the mouse, i'd like it to be when hovering with another element..
Is this possible?

UPDATE

Fiddle:
https://jsfiddle.net/0apuqnxd/27/

$('.elementsDiv').droppable({
  over: function(){
    $(this).css('background-color', 'red');
  },
  out: function(){
    $(this).css('background-color', '');
  }
});

I'm starting to get close, now my problem is that is that if another element is crossing by, the color changes back when "out".

Björn C
  • 3,860
  • 10
  • 46
  • 85
  • [jquery droppable](https://jqueryui.com/droppable/#accepted-elements) has this functionality out of the box (`hoverClass` property). You need to use both `.draggable` and `.droppable` plugins – Catalin Jun 01 '16 at 06:35
  • @RaraituL But i cannot make my `.draggable` element's also `.droppable`. Because when i drop an element it is appended to that "dropzone". This means that i will have alot of dropzones?! – Björn C Jun 01 '16 at 06:39
  • You want the color to change on drop? in that case you can use `drop` method? – Sandeep Nayak Jun 01 '16 at 07:09
  • @SandeepNayak I like to change the color of a draggable element to change, if it's dropped on another draggable element. (Not droppable element) – Björn C Jun 01 '16 at 07:12

1 Answers1

-1

if its ok with you to use another javascript library

try this one

go down to "Drag and drop" sample you will find the code to what you want.

http://interactjs.io/

Tawfiq abu Halawah
  • 1,214
  • 1
  • 12
  • 20
  • Thank you. I will look into this! – Björn C Jun 01 '16 at 14:22
  • I cannot see how this framework should be better than Jquery? – Björn C Jun 02 '16 at 06:40
  • I did not say that its better or worst than jQuery. what I said that the code in "Drag and Drop" section might help you solving your problem, since it has many color changes in the areas. – Tawfiq abu Halawah Jun 02 '16 at 07:02
  • ok, But it still doesn't solve my problem?! Jauery has a "over" and it works just like this. But thats not what i want. I´d like a function that tells me if i drop an element on another draggable element.. i cannot see that on the link you gave me? – Björn C Jun 03 '16 at 18:55