$(function() {
// Vars.
var $document = $(document),
$wrapper = $('#wrapper'),
$placeholder = $('<div class="placeholder"></div>'),
isDragging = false,
hasDropTarget = false,
isMobile = (navigator.userAgent.match(/(like Mac OS X|Android|Windows Phone)/) !== null);
// Bind events.
$wrapper
.touch({
// Turn on document tracking for smoother dragging.
trackDocument: true,
// Set drag threshold to zero for maximum drag sensitivity.
dragThreshold: 0,
// Set drag delay to zero for fastest drag response.
dragDelay: 0,
// Turn on drop filter (true = limit to siblings of item being dragged).
dropFilter: true,
// Delegate touch events to items.
delegateSelector: '.item',
// Lower tap and hold delay.
tapAndHoldDelay: 250,
// Prevent default events for drag events. Ordinarily this takes a boolean value, but in the case
// of this demo we're doing the following to prevent:
//
// - If we're *not* on a mobile device, always prevent default drag events.
// - If we *are* on a mobile device, only prevent default drag events when we're in a "tap and hold" gesture.
preventDefault: {
drag: (!isMobile ? true : function(t) {
return t.inTapAndHold;
})
}
})
.on((!isMobile ? 'dragStart tapAndHold' : 'tapAndHold'), '.orderable > .item', function(event, o) {
// Stop propagation.
event.stopPropagation();
// Vars.
var $this = $(this),
scrollLeft = $document.scrollLeft(),
scrollTop = $document.scrollTop();
// Already dragging? Bail.
if (isDragging)
return;
// Set dragging state.
isDragging = true;
// Size placeholder.
$placeholder
.css('width', $this.outerWidth() + 'px')
.css('height', $this.outerHeight() + 'px');
// Size and position drag element and mark it as dragging.
$this
.css('width',...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.