Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.0/jquery-ui.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
<!--[if IE]>
  <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<style>
  article, aside, figure, footer, header, hgroup, 
  menu, nav, section { display: block; }
  
  .items { 
    position: absolute;
    cursor: pointer;
    background: #FFC400;
    -moz-box-shadow: 0px 0px 2px #E39900;
    -webkit-box-shadow: 1px 1px 2px #E39900; 
    box-shadow: 0px 0px 2px #E39900;
    -moz-border-radius: 2px; 
    -webkit-border-radius: 2px; 
    border-radius: 2px; 
  }
</style>
</head>
<body>
  <div class="items"></div>
  <div class="items"></div>
  <div class="items"></div>
  <div class="items"></div>
</body>
</html>
 
$(function () {
  monkeyPatch_mouseStart();
  $('.items').each(function(i) {
    $(this).css({
      top: (80 + Math.random() * i) + '%',
      left: (80 + Math.random() * i) + '%',
      width: (100 + 200 * Math.random() * i) + 'px',
      height: (10 + 10 * Math.random() * i) + 'px',
      '-moz-transform': 'rotate(' + (180 * Math.random() * i) + 'deg)',
      '-o-transform': 'rotate(' + (180 * Math.random() * i) + 'deg)',
      '-webkit-transform': 'rotate(' + (180 * Math.random() * i) + 'deg)',
    });
  });
  
  $('.items').draggable({
     start: function(event, ui) {
       console.log("x: ", ui.offset.left, ui.helper[0].offsetLeft);
        console.log("y: ", ui.offset.top, ui.helper[0].offsetTop);
     }
  });
});
 function monkeyPatch_mouseStart() {
      // don't really need this, but in case I did, I could store it and chain
      var oldFn = $.ui.draggable.prototype._mouseStart ;
      $.ui.draggable.prototype._mouseStart = function(event) {
        var o = this.options;
    
        //Create and append the visible helper
        this.helper = this._createHelper(event);
    
        //Cache the helper size
        this._cacheHelperProportions();
    
        //If ddmanager is used for droppables, set the global draggable
        if($.ui.ddmanager)
          $.ui.ddmanager.current = this;
    
        /*
         * - Position generation -
         * This block generates everything position related - it's the core of draggables.
         */
    
        //Cache the margins of the original element
        this._cacheMargins();
    
        //Store the helper's css position
        this.cssPosition = this.helper.css("position");
        this.scrollParent = this.helper.scrollParent();
    
        //The element's absolute position on the page minus margins
        this.offset = this.positionAbs = { top: this.element[0].offsetTop, 
                                           left: this.element[0].offsetLeft };
        this.offset = {
          top: this.offset.top - this.margins.top,
          left: this.offset.left - this.margins.left
        };
    
        $.extend(this.offset, {
          click: { //Where the click happened, relative to the element
            left: event.pageX - this.offset.left,
            top: event.pageY - this.offset.top
          },
          parent: this._getParentOffset(),
          relative: this._getRelativeOffset() //This is a relative to absolute position minus the actual position calculation - only used for relative positioned helper
        });
    
        //Generate the original position
        this.originalPosition = this.position = this._generatePosition(event);
        this.originalPageX = event.pageX;
        this.originalPageY = event.pageY;
    
        //Adjust the mouse offset relative to the helper if 'cursorAt' is supplied
        (o.cursorAt && this._adjustOffsetFromHelper(o.cursorAt));
    
        //Set a containment if given in the options
        if(o.containment)
          this._setContainment();
    
        //Trigger event + callbacks
        if(this._trigger("start", event) === false) {
          this._clear();
          return false;
        }
    
        //Recache the helper size
        this._cacheHelperProportions();
    
        //Prepare the droppable offsets
        if ($.ui.ddmanager && !o.dropBehaviour)
          $.ui.ddmanager.prepareOffsets(this, event);
    
        this.helper.addClass("ui-draggable-dragging");
        this._mouseDrag(event, true); //Execute the drag once - this causes the helper not to be visible before getting its correct position
    
        //If the ddmanager is used for droppables, inform the manager that dragging has started (see #5003)
        if ( $.ui.ddmanager && $.ui.ddmanager.dragStart) $.ui.ddmanager.dragStart(this, event);
    
        return true;
      };
  }
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers