Jump to content
Search Community

gosu

Members
  • Posts

    11
  • Joined

  • Last visited

Posts posted by gosu

  1. Okay it turns out the extern file provided is almost doable. I needed to add some support for Draggable, may help someone:

    var TweenMax = {};
    
    var Draggable = {};
    
    Draggable.create = function () {};
    
    Draggable.prototype.hitTest = function () {};
    
    Draggable.prototype.applyBounds = function () {};
    
    Draggable.prototype.onDragStart = function () {};
    
    Draggable.prototype.onComplete = function () {};
    
    Draggable.prototype.onStart = function () {};
    
    Draggable.prototype.onDrag = function () {};
    
    Draggable.prototype.onPress = function () {};
    
    Draggable.prototype.onRelease = function () {};
    
    Draggable.prototype.onDragEnd = function () {};
    
    TweenMax.prototype.lagSmoothing = function () {};
    
  2. Hey, I am using Draggable with hitTest() to determine possible drop spots.

    I needed more advanced solution to get the drop spots ordered by percent covered (if draggable object is dropped on 2 or more droppable spots - I needed the one which has the most overlap area covered). Otherwise you end up with let's say 1 draggable element being dropped on 2 possible droppable elements (both having the minimum threshold), it won't matter if you cover one of the elements waaaay more than the other.

     

    For this I modified Draggable.js

    if (isRatio) {
            threshold *= 0.01;
            area = overlap.width * overlap.height;
            // edit here
            return [(area >= r1.width * r1.height * threshold || area >= r2.width * r2.height * threshold), area];
    }
    return (overlap.width > threshold && overlap.height > threshold);
    

     and onDragEnd: 

    lastOverlapScore = 0; 
    var highestScoreObject = null;
    
    $.each(droppables, function (i, obj) {
        var overlap = draggable.hitTest(obj, '25%'); // some threshold
    
        if (Array.isArray(overlap) && overlap[0] === true && lastOverlapScore < overlap[1]) {
            lastOverlapScore = overlap[1];  
            var highestScoreObject = obj;
            
        }
    
    });
    
    // highestScoreObject is the element with highest coverage area
    

    This may help someone looking for similar result or may be in use if you decide to add way to get the score.

    It would be less hacky solution of I could get the area from Draggable without having to modify it, but though I'm happy it works.

     

  3. I think he's trying to say that when you try to drag the green square by holding it at the very right bottom edge,

    and you go outside red bordered rectangle (#placeholder) and the square gets resized, the position of the cursor stays very far

    from the center of the dragged square.

  4. Is there any chance to see grouping of Draggable elements so that when you drag single element of a group,

    all elements of the group are being dragged. There's such functionality in YUI:

     

    http://yuilibrary.com/yui/docs/api/classes/DD.Drop.html#method_addToGroup

     

    http://yuilibrary.com/yui/docs/api/classes/DD.Drop.html#method_removeFromGroup

     

    Something like:

    var draggable1 = Draggable.create(element1);
    draggable1.addToGroup('group');
    
    var draggable2 = Draggable.create(element2);
    draggable2.addToGroup('group');
    
    
×
×
  • Create New...