Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function create_drop_targets() {
- $('li a')
- .bind('dropstart', function(event) {
- })
- .bind('drop', function(event) {
- })
- .bind('dropend', function(event) {
- });
- }
- var drop = $.event.special.drop = {
- setup: function(){
- drop.$elements = drop.$elements.add( this );
- drop.data[ drop.data.length ] = drop.locate( this );
- },
- locate: function( elem ){ // return { L:left, R:right, T:top, B:bottom, H:height, W:width }
- var $el = $(elem), pos = $el.offset(), h = $el.outerHeight(), w = $el.outerWidth();
- return { elem: elem, L: pos.left, R: pos.left+w, T: pos.top, B: pos.top+h, W: w, H: h };
- }
- drag: function(draggable, event) {
- //If you have a highly dynamic page, you might try this option. It renders positions every time you move the mouse.
- if(draggable.options.refreshPositions) $.ui.ddmanager.prepareOffsets(draggable, event);
- ...
- $(".cocktails").draggable({
- refreshPositions: true,
- });
- //This will be called every time the user moves the draggable helper.
- function onDrag(event, ui) {
- //We need to re-aquire the drag handle; we don't
- //hardcode it to a selector, so this event can be
- //used by multiple draggables.
- var dragHandle = $(event.target);
- //If refreshOptions *was* true, jQueryUI has already refreshed the droppables,
- //so we can now switch this option back off.
- if (dragHandle.draggable('option', 'refreshPositions')) {
- dragHandle.draggable('option', 'refreshPositions', false)
- }
- //Your other drag handling code
- if (/* logic to determine if your droppables need to be refreshed */) {
- dragHandle.draggable('option', 'refreshPositions', true);
- }
- }
- $("#mydraggable").draggable({
- //Your options here, note that refreshPositions is off.
- drag: onDrag
- });
- $(window).resize(function () {
- $(".draggable").draggable("option", "disabled", true);
- $(".draggable").draggable("option", "disabled", false);
- });
Add Comment
Please, Sign In to add comment