javascript:
(function($){
if(!$ || !$.fn.on){return alert('missing $ or $.fn.on');}
// drag any element (max one at a time)
// .drag .draghandle
// tip: to drag anything; inspect any element, then open console and do $($0).addClass('drag draghandle');
// TODO: currently only supports position:fixed dragging; also allow position:relative and position:absolute dragging?
// TODO: prevent text selection when dragging. especially if the draghandle has text in it.
// TODO: prevent odd things happening when dragging from draghandle that is/has a link in it (holding ALT helps with this).
var log = (console && typeof console.log === 'function') ? console.log : function(){};
var drag = {
dragging:false,
dragtarget:null,
// dragstart_target_position:null,
dragstart_target_offset:null,
// dragstart_target_topleft:null,
dragstart_mouse_x:null,
dragstart_mouse_y:null,
z:0
};
function init(){
css();
$(document).off('.ev_drag');
$(document).on('dragstart.ev_drag mousedown.ev_drag ','.draghandle', DragStart );
$(document).on('dragend.ev_drag mouseup.ev_drag',DragStop);
$(document).on('mousemove.ev_drag', DragMove);
}
function css(){
$('style#style_drag').remove();
var $s = $('<style>', {id:'style_drag'});
$s.appendTo( $('head,body').eq(0) );
$s.append('.drag.dragging { outline: 1px dashed #888; }');
$s.append('.draghandle { cursor: move; }');
// TODO: make this optional? could be in the way of something you want to click on (e.g. closing cross or similar in top right)
// add a very tiny drag handle; also helps against selecting text when dragging and odd behaviour when starting dragging above a link:
// \2194 leftright arrow and \2195 updown arrow. havent found the character equivalent of the cursor:move icon yet.
$s.append('.draghandle:hover::before{ cursor: move; content: \'\\2194\\2195\'; position: absolute; top: 0; right: 0; background: #fff; color: #000; z-index: 999; line-height: 1; font-size: 14px; }');
}
function...
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.