Drag and drop activity jquery? - javascript

I'm trying to create drag and drop activity where left side have some images and we have to drop that images into right inside the targeted div. can somebody help me or guide me on this i am new in html5 and jquery?
also if the draggable item is not match with that particular targeted div then it comes back to its original place
logic is like that
img drag
{
if(img == targeted div){
img place inside div
}
else{
it reverts to its original position
}
and visa versaaa

You need jquery UI draggable and droppable for this. You can refer them here: http://api.jqueryui.com/droppable & http://api.jqueryui.com/draggable .
I created a fiddle for it. So the images having class "yes" will only be dropped in the div, rest of them will not be dropped.
Here is the sample code:
$('.drag img').draggable({
revert: 'invalid',
});
$('.drop div').droppable({
accept: '.yes'
});
Jsfiddle link: http://jsfiddle.net/p2taQ/

Related

drag and drop from master to detail view in sapui5

I would like to enable drag and drop within an sapui5 app. To do so I'm using the jQuery draggable and droppable widgets. Whenever I'm dragging an element from the master view to the detail view or vise versa the dragged element is hiding behind the other view. The drop is still recognized, the element is just don't show up. Basically both views are just div's. It could have something to do with the overflow property but I'm not getting any sense into it.
I'm using those parameters on my draggable function:
draggable({
helper: "clone",
cancel: true,
cursor: "pointer",
stack: "
})
Here's a sample jsbin: http://jsbin.com/werewuf/4/edit?html,output
As the sapMNav sapMSplitContainerMaster sapMSplitContainerMasterVisible element having overflow : hidden property, any child of this parent can not be seen visible out of this container.
Set 'overflow' : 'visible' for parent element and also for dragButton.$().parent().css("overflow-y", "visible").css("overflow-x", "visible");
$('.sapMSplitContainerMasterVisible').css('overflow', 'visible');
JSBin Demo

Stop the dragable event when this related div tag reached 100%?

I was tried to drag the div (class = scale_roll) tag by dragging the another div (class =scale_cap).
When the div scale_cap is dragging it's related scale_roll div tag also move.
But my problem is scale_cap dragging cann't stop when the scale_roll div tag was reached 100%.
I want to don't drag the div tag after the visible area. or i want to drag only the 100%.
Js Fiddle
First of all you fully read the Draggable. jQuery have the option for add the handle to the div.
So you don't work hard for add the handle to the drggable element.
create the handle <div> inside the draggable div. Then add and use this
$( ".scale_roll" ).draggable({
axis: "x",
containment: 'parent',
handle:'.scale_cap',
});
Working fiddle

Add image and allows edit

Hi I am very new in JQUERY. It is a new thing to me.
I was tasked to be able to collect and place and Image into an area where the user is allowed to actually move the object to any position he/she prefers.
At the current point I am at, I'm not sure how to actually create a JQUERY that once click on the image, it will appear on the area where user can move the picture.
Would really appreciate help here as i'm really new to this.
The link for somethinng similar would be like as follow
Example
Like catifier, images will be placed at the side. Once click on an image, the image will be brought to the black box and from there user can move the image around.
jsBin demo
Using jQuery and jQuery UI is easy as that:
<div id="thumbs">
<img src="cat1.jpg">
<img src="cat2.jpg">
</div>
<div id="dropper"></div>
css:
#thumbs{float:left;width:170px;}
#dropper{background:#223;height:400px;overflow:hidden;}
jQuery/UI:
$(function(){ // DOM ready
$('#thumbs img').draggable({
revert: "invalid", // revert to original pos. if not dropped into droppable
containment: "body" // prevent the user from dragging the image out of sight
});
$('#dropper').droppable(); // The droppable element
});
For more info see:
http://jqueryui.com/draggable/ and http://jqueryui.com/droppable/

align the dropped divs in a container div

Description
I have a container div that has little divs with pictures on them..
what works perfect is when I click any one of them(div) it comes out and do stuff that is assigned to it.
Now I can drag any div I want back into the container but the problem is the div when dropped in the container stays at the place where it is left. I want to align all the divs in the container at the top when ever droped.
e.g when I drag any div back into the container it should be aligned with all other divs in the container.
What have I tried ?
I have tried to give the dropped div
position: inherit with jquery . but that only works if there is 1 div to drag and drop.
Have I searched StackOverflow form answers ??
Yes I have and I found a solution
found solution demo
but it involves the clonning of the divs which in my case is not required.
Can any one help me ??
Would it solve your problem if you add a "remove" line in your solution? E.g. :
$("#droppable").droppable({
drop:function(e,ui){
if($(ui.draggable).parent().attr("id")!=$(this).attr("id")){
var clone = $(ui.draggable).clone();
clone.removeAttr("style");
clone.appendTo($(this));
$(ui.draggable).remove(); // Remove original element
}
},
revert:true
});
Fiddle demo: http://jsfiddle.net/lparcerisa/xu2dm7gj/1/

Combining revert with jQuery draggable/droppable

I'm using the drag and drop plugin with jQuery UI. I'd like to make it so that the draggable container can only be dragged and dropped on the container. In the demonstration:
http://jqueryui.com/demos/droppable/#revert
It has 2 options. One is to revert when it drags to the container, the second is to revert when it isn't dragged to the container.
Is there a way to combine these two? I don't want to be able to drag the #draggable container anywhere where there isn't a #droppable container.
As stated above, I found the solution by adding :
$('#draggable2').remove();
$('#draggable').draggable({ revert: true });

Categories

Resources