Making an item draggable
Viewers: in countries Watching now:
Drag-and-drop functionality is perfect for any game or interactive web project. Edge Animate makes it easy to implement. Plus, the drag-and-drop interactions you add work even on smartphones and tablets. Learn how to create draggable objects, add target areas where users can drop them, create reactions to those drops, and change content and object positioning accordingly. Author Paul Trani walks you through each step of the process in this project-based course.
- Creating graphics and importing them into Edge Animate
- Adding animation and interactivity
- Making items draggable
- Adding a droppable target area
- Controlling multiple objects
- Resetting positions of objects
- Testing and publishing your project
Making an item draggable
So I want to reference the jQuery UI documentation when doing that. So I'm going to launch a browser. And on jqueryui.com notice right over here my interactions, draggable, droppable, all sorts of things we can do. In fact I'm going to select draggable. And you can see how you can drag around this box. And there's other capabilities such as constraining the movement, all sorts of different things you can do. So I encourage you to explore the API documentation, which is exactly what I'm doing.
In fact, as I scroll down, you can see all the various options, the methods. But you'll see quite simply, its just adding a .dragable. So going back into Edge Animate. Selecting my eyes, and again right down here this is just an easy way to open up the actions. This is the actions I have for mouse over. Now I don't want to play that animation, so I'm going to eliminate that part but what I am going to do is I'm going to type in sym. That's going to target that symbol. Dollar sign since it's jQuery and then the name of the symbol.
In this case it's going to be eyes. And then .draggable. Open close parenthesis, end with a semi colon to complete this one line. And with that done, I will save this page and preview it in a browser. For the eyes, as I click on the eyes you can see how I can move them around. Easy enough, I could do the same thing for the mouth as I roll over that mouth that has functionality involved with it. So how would I take advantage of dragable there? Well it's pretty much the same deal.
In fact, I can go back into the eyes and it's going to be this same line. So I'm going to select it, Cmd+C to copy or Ctl+C if you're on a PC. Going to my mouth right here. Selecting the Open Actions button there. And rather than playing those two timelines I'm just going to paste in that line that I copied and change this to mouth. Easy enough. Doing a Cmd+Enter, Ctl+Enter, if you're on a PC. I can now drag around the mouth as well as the eyes. But there's additional functionality available as well, in fact, as I go back into jqueryui.com/draggable, right down in here you can start to see the different things you can do.
In fact, I want to actually change the opacity. So as I click on it I want to give an indication that I'm dragging it around. As well as I want to revert back to its original position. So I'll select opacity. And you can see it's this simple. It'll make it 35%. So I'll copy that line. As I'll scroll down you can see the revert. I'm going to take advantage of that as well. But let's start with opacity. By selecting my eyes. Opening up the Actions for it.
Right in those parentheses. Pasting that in. Opacity, 35%. And then I want to do a comma and this is where I'll add my revert. If we go back to our browser, we'll take a couple different parameters. You'll have basically true, invalid, valid or true. And I want to do invalid. If it's not dropped on a droppable item, then put it back in its place. Revert invalid. That's what I'm going to go with. Right in here. And in quotes. Invalid.
So, it'll change opacity and should, as I run this again, it should actually go back to its original position. So there's my opacity change, as I release, it goes back into it's original position. That's excellent in fact, I'm going to do this once more. Specifically for the mouth. Taking those same, parameters, right in here, copying them. For my mouth, pasting them in and now as I save this and I run it.
I now have two elements that I can drag. Around and as I release they go back into their original location. So I encourage you to try that out for yourself as well as explore the additional functionality options, methods, and events that are available thanks to the JQuery UI draggable capabilities.
There are currently no FAQs about Creating Drag-and-Drop Functionality with Edge Animate.