I'm very new to j Query UI. I was trying to design a drag&drop game. I looked into lots of answers in stack overflow but not getting very similar examples(or maybe I couldn't figure out).
Basically, I tried to do a recycling game where you can drag and drop different items either to the recycle bin or trash bin. All the spans are image actually. I meant to put those bins side by side, the CSS worked for image before but not for span now.
Here's the fiddle for it. the dragging works on my browser but not working in fiddle.
https://jsfiddle.net/92dty8cq/9/
[code, it's all in fiddle]
What I tried to figure were two thing:
1.How to make my items disappear when I drop them in either of the bins?
2.How to count the right answer and show the total score when you finish playing the game?
And also why it works locally but not on fiddle?
I kinda have a logic that I should count the distance(data-x/y) and match the classes/data-type of the bin and items but had trouble coding it out.
Any suggestion? Any hint will be really appreciate it!
Here is a working JSFiddle.
1. How to make my items disappear when I drop them in either of the bins?
draggable
documentation for.drop()
accept
option.2. How to count the right answer and show the total score when you finish playing the game?
You can initialize a score of
0
and increment it every time adraggable
is accepted by adroppable
.And for the draggable, add a
hide()
method,That combined with the droppable code,
...achieves what you're looking for.
The HTML should be like so:
Notice that "
.recyclable
" and ".notrecyclable
" are classes for thedrag-item
s and that "#recyclebin
" and "#trashbin
" are ids for thedropzone-container
s.This allows you to use the
accept
option for thedroppable
objects correctly.3. Why doesn't it work on JSFiddle?
To see why the dragging is not working on JSFiddle, take a look at the JavaScript console in your browser. You will see the following two errors:
Mixed Content: The page at 'https://fiddle.jshell.net/92dty8cq/9/show/' was loaded over HTTPS, but requested an insecure script 'http://code.jquery.com/jquery-1.10.2.js'. This request has been blocked; the content must be served over HTTPS. fiddle.jshell.net/:1
Mixed Content: The page at 'https://fiddle.jshell.net/92dty8cq/9/show/' was loaded over HTTPS, but requested an insecure script 'http://code.jquery.com/ui/1.11.4/jquery-ui.js'. This request has been blocked; the content must be served over HTTPS.
The reason why this is happening is because JSFiddle is a secure page (over HTTPS), but you are including the two scripts as insecure resources (over HTTP).
The script tags in your HTML should be:
Here is a full output of the errors in the console:
Resources
For next steps, review the JQuery UI documentation for
Hope that helps!