Issue with overlapping Drag and Drop connecting with wrong components - javascript

Link to Video: https://youtu.be/16OXCpw3MBs
I have a stange one, I have three div's two of which scroll horizontal/vertical all of the divs have cards in that are draggable to enable moving of cards and ordering them. All works fine until you scroll one of the div's so that the columns are "under" another div.
I have attached a video to try to show this as I can't think of of an easy way to explain the issue.
Here is the drag and drop code:
$(function () {
$('ul.sort')
.sortable({
containment: 'document',
helper: 'clone',
appendTo: "body",
connectWith: ".sortable",
stop: function (e, ui) {
//Functions removed for security - some AJAX made here
}
},
})
.disableSelection();
});
I thought Z-Index would sort it but the draggable component is connecting with droppable elements under the element I want it to connect with.
Thanks in advance.
Link to Video: https://youtu.be/16OXCpw3MBs

Related

jQuery touch-punch draggable in list: scroll and drag interferes (mobile device)

I am trying to build a list of draggables but the drag event somehow interferes with the scroll event on mobile devices (tested on a windows tablet, on desktop pcs it works fine). I can either scroll or drag but not both. If I set "-ms-touch-action" and "touch-action" to none, I can scroll, if I don't set it, I can drag.
Touch-punch is included as well. I think, the best way to solve this problem would be triggering the drag event by holding the item for one or two seconds, but I can't get that to work.
It is important that the overflow of the list is set to visible on start and back to '' on stop, because I have to drag the items out of the divs boundaries and my application doesn't allow me to do it in any other way.
You can test the code here: http://jsfiddle.net/LQuyr/344/
Hope you guys can help me. Thanks.
// draggable
$('#sortable li').draggable({
scroll: false,
helper: 'clone',
start: function(e, ui) {
$('#sortable').css('overflow', 'visible');
},
stop: function(e, ui) {
$('#sortable').css('overflow', '');
}
});
Maybe the delay option is what you're looking for...
$('#sortable li').draggable({
delay: 300,
scroll: false,
helper: 'clone',
start: function(e, ui) {
$('#sortable').css('overflow', 'visible');
},
stop: function(e, ui) {
$('#sortable').css('overflow', '');
}
});

JQuery UI draggable not dropping beyond certain point scroll horizontal

function init_gearbrowser_draggables() {
$("#gearbrowser_product_list div.product").draggable({
start: function() {
counts[0]++;
},
containment: '#sandbox_space',
refreshPositions: true,
helper: 'clone',
appendTo: '#sandbox_space',
zIndex: 12,
delay: 200,
scroll: false,
scope: "sandbox_items",
stop: function(event, ui) {
sb_index_items();
}
});
} // init_gearbrowser_draggables
// define drop space
$('#dragspace').droppable({
scope: "sandbox_items",
accept: "div.product",
tolerance: "fit",
drop: function(event, ui) { //on drop
// alert("dropped");
ui.draggable.attr("id", "sb_item");
item_pos_top = ui.position.top;
item_pos_left = ui.position.left;
ui.draggable.css("top", item_pos_top);
ui.draggable.css("left", item_pos_left);
ui.draggable.detach().appendTo($(this));
}
});
Hello everyone,
I facing a (probably rather simple) glitch in a JQuery UI draggable/droppable setup.
The below fiddle shows:
a left menu for new draggable divs (dog) a background droppable area
with
existing draggable items (red squares)
a size of 3000 x 2000 and it's parent set to overflow:auto;
DOM id: #sandbox_space
It does scroll fine
has a beach background to better indicate the position while scrolling
The problem:
Dragging the dog to the right onto the droppable #dragspace (is #sandbox_space.ul) works fine unless
we first scroll to the right to about 75%.
Dragging the dog to the right will then result hitting an "edge".
So it is not possible to drag the dog beyond that point.
Trying to do so by scrolling 100% to the right, results in the dog
being placed on the far left.
"containment" and "appendTo" options in .draggable()
for the dog are set to #sandbox space, which is the full 3000 x 2000 px.
This only happens with a horizontal scroll past approx 75%.
It does not happen with a vertical scroll.
I understand that this is either a problem with the draggable/dropppable options
in JS or a rather stupid CSS-realted issue that I cannot figure out at this point.
Your tips are highly appreciated.
Thanks a lot !
https://jsfiddle.net/60evfLdh/12/

jQuery ui draggable element gets under other draggable elements

I have a style problem with jQuery Ui draggable elements.
here what i have
FIDDLE
As u can see, i have two droppable areas , in each area elements are draggable, and can drag and drop element from one block to another
The only problem here , that when i am dragging element from top block to below block, the dragging element gets under droppable are elements, but when i am dragging from bottom are to top there is no such problem.
Here is the code for dragging
$(".slide").draggable({
// brings the item back to its place when dragging is over
revert:true,
// once the dragging starts, we decrease the opactiy of other items
// Appending a class as we do that with CSS
start: function(event, ui) { $(this).css("z-index", a++); },
drag:function () {
$(this).removeClass('droped');
},
// adding the CSS classes once dragging is over.
stop:function () {
$(this).addClass('droped');
},
zIndex: 10000,
snapMode: "inner"
});
Can anybody help me please, i am working on it already 2 days, and can't figure out what is the problem, i have tried to change z-index positions of every block, but no result;
I found out that my code only worked the first time - i removed some z-indexes from your JQuery ánd your css, now it is working for me every time:
http://jsfiddle.net/zbo7g5nz/5/
My jFiddle doesnt seem to get updated to share.. Here is working code:
$(".slide").draggable({
// brings the item back to its place when dragging is over
revert:true,
// once the dragging starts, we decrease the opactiy of other items
// Appending a class as we do that with CSS
start: function(event, ui) { $(this).css("z-index", a++); },
drag:function () {
$(this).parent().css('z-index', '10001');
$(this).removeClass('droped');
},
// removing the CSS classes once dragging is over.
stop:function () {
$(this).parent().css('z-index', '10001');
$(this).addClass('droped');
},
zIndex: 10000,
snapMode: "inner"
});
I gave a z-index to the ul holding the li that was higher than the li of the list that was below.
Avoid tricks and go with divs instead of UL or LI for further compatibility.
Also, you don't need to listen to the start event to setup the z-index property. The .draggable() api exposes the zIndex prop for that reason.
Here is the demo working:
http://jsfiddle.net/zbo7g5nz/8/

jQuery UI sortable revert: Reverting to the top left

If you take the following example: http://jsfiddle.net/99yVq/2/ and drag one of the top portlets and drop into the top of the black area (representing a menu), it reverts to the top left before snapping into position. I'm presuming this is related to my method of animation (showing and hiding an invisible placeholder) as when I remove the .show and .hide revert functions as expected.
.sortable call:
$( ".content" ).sortable({
handle: '.portlet-header',
items: '>:not(.fixed)',
revert: true,
start: function(e, ui){
$(ui.placeholder).hide(300);
},
change: function(e,ui) {
$(ui.placeholder).show(300);
}
});
$( ".content" ).disableSelection();
Does anyone know the cause of this?
Thanks in advance.
Edit They also do it if you drag them way off to the right, or onto the fixed portlet. also stripped down the test case.
Update for Answer
Taking into account the answer below I have updated the fiddle using .animate and setting the widths rather than hiding the placeholder. The animation is not quite as rugged but it's good enough!
The item you want to sort is appended to the placeholder (if set). As you are hiding the placeholder, theres no display style left and the item is appended to the body instead. If you want to keep the placeholder but want to "hide" it, think about styling it that way - with keeping it as a block element.
start: function (e, ui) {
$(ui.placeholder).css('width', 0);
},
change: function (e, ui) {
$(ui.placeholder).css('width', auto);
}

Can I display:none part of a jQuery UI draggable and still keep the cursor in place somehow?

I have a number of draggables with images in them that I want to drop into folders. To conserve space (and make more draggables visible on the screen at one time), I'm hiding the images with CSS during the drag. How can I keep the mouse on the draggable when the images disappear?
Here's an example of what I'm seeing, just using a simple draggable box:
$( "#draggable" ).draggable({
revert: "invalid",
cursor: "move",
scroll: false,
cursorAt: { top: 5, left: 5 },
start: function(event, ui) {
$('img').addClass('hidden');
},
stop: function(event, ui) {
$('img').removeClass('hidden');
}
});
http://jsfiddle.net/fBPdF/
The hidden class uses display:none; to hide the images. As you can see in the fiddle, dragging the first image works fine, and the mouse tracks along in the upper left-hand corner of the box while you drag. When you drag the second, the mouse floats off to the side because the cursorAt value has already been set when the images get removed.
I'd prefer not to use a helper clone (because that makes the move look more like a copy), but that's the only way I've found so far to make it work. I tried resetting the cursorAt inside a timeout in the start function, but it didn't seem to have an effect.
Is there a way to keep the cursor and the draggable together somehow?
Try to change opacity. The hidden attr get off the element from "index".
.hidden {
opacity: 0;
}
http://jsfiddle.net/eEgTL/

Categories