Jump to content
Search Community

slopps

Members
  • Posts

    8
  • Joined

  • Last visited

Recent Profile Visitors

2,103 profile views

slopps's Achievements

16

Reputation

  1. Thank you Blake! That's a great point about binding, that should've occurred to me. Great points on the scoping too; thank you for pointing that out. That was due to porting this as quickly as possible to codepen from a component that exists within a larger app, where the "this" context is referring to the component which is encapsulated within a commonjs module, which is created using new. I admittedly did a poor job on the pen... Thanks so much for the quick and thorough response!
  2. Solved. While the PointerEvent target is still showing non-Draggable, I was able to stop the errors by setting this.$currentDragItem in onDragPress instead of onDragStart. I now realize this is not an issue with Draggable as is it is merely passing along the PointerEvent, which is reflecting what the mouse is currently over. I'm also scoping my callbacks differently so that I'm not able to get the draggable instance from 'this'. If scoped normally, you wouldn't need to rely on the PointerEvent to get the current drag item, as you could use 'this' to get the Draggable instance. Hope this helps someone in the future!
  3. Very rarely, about 1 out of 100 times (sometimes you have to re-run the pen even), if you try to drag these items around very rapidly (as in click, drag, release and immediately click and drag again, over and over) Edit: to replicate consistently, place the mouse on the last pixel on any edge of DragItem1 (so the very first pixel where your mouse turns into a drag icon), then drag away from that edge (so if you choose bottom edge, drag downward). You will see via the console logs that the PointerEvent target inside onDragStart is a totally non-draggable element. In the onDragPress, the target is correctly '.drag-item', whereas in onDragStart, the target is 'drag-item__wrapper' (and sometimes other elements, depending), which is not a Draggable. I put in a console warning to show when this happens. I feel like this is happening because once the mouse moves 1 pixel away, it is no longer over/touching the drag item but instead over what's under the mouse? So perhaps I should move most my logic out of onDragStart? Screenshot of console below (the error about update() is happening because the target is not a Draggable). Any help is greatly appreciated!
  4. If you look at the docs, one of the examples says //checks if at least 50% of the surface area of either element is overlapping: if (this.hitTest("#element3", "50%")) { //do stuff } therefore, it checks if 50% of either element is overlapping with the other
  5. You're right on both accounts. I was going to argue that it was being calculated anyway, but looking at the hitTest implementation I see that the area is only calculated if a ratio is passed. Perhaps it could become a new function, getOverlapArea or some such? It goes without saying, I defer to you as this is one of the most well made libraries I've used (thank you, btw!). Not sure if percentage would be as necessary since area could also be used for comparison between the drop-zones to determine dropspot "most-over." In the meantime, if anyone needs it you could get the overlap area of two elements with the following function (borrowed mostly from Draggables own hitTest implementation): *Note: this is not as backward compatible as gsaps own hitTest code, so use at your own risk: getOverlapArea = function(element1, element2) { if(element1.jquery) element1 = element1[0]; //convert from jquery to dom element if(element2.jquery) element2 = element2[0]; //convert from jquery to dom element var rect1 = element1.getBoundingClientRect(); var rect2 = element2.getBoundingClientRect(); var xOverlap = Math.max(0, Math.min(rect1.right , rect2.right) - Math.max(rect1.left, rect2.left)); var yOverlap = Math.max(0, Math.min(rect1.bottom, rect2.bottom) - Math.max(rect1.top, rect2.top)); return xOverlap * yOverlap; };
  6. I would actually argue that the hitTest() function should return a percentage rather than a boolean. The percentage would represent the overlap. 0 would mean no hit detected, anything above zero would represent the percentage of overlap. This would be useful when the item was touching multiple drop spots, when you want to know which drop spot the drag item was most over.
  7. Thank you! Seems to work very nicely even with the animation. I was initially not willing to change the transform origin due to other constraints, but they're easier to work around than this would otherwise be. I will note, if you rotate the drag item in addition to scaling, this stops working as expected. Fortunately I was able to talk my project managers into getting rid of the rotation. Thank you again
  8. Just finished making these two short codepens to demonstrate. This Draggable has a separate drag handle for the drag item, and on release it scales the entire drag item up. If you click on the handle while it's scaled up, I want the item to shrink back to it's normal size only while you are dragging. However, I can't figure out how to make it stay under your mouse where you actually clicked the handle. codepen 1 - instantly scale-down: http://codepen.io/anon/pen/VerJdJ codepen 2 - animate scale-down (this is what i would prefer if possible): http://codepen.io/anon/pen/JGOQYZ I thought maybe while scaling, if I could change the transform origin to where the mouse pointer is that would fix it, but unfortunately there are other coordinates in the application that rely on the transformOrigin being 50%, 50%. Is there a way to do this? Outcome: 1.) The item shrinks but is no longer under your mouse pointer. Even attempting to relocate it manually seems wonky (see codepen and other things I have tried below) Expected Outcome: 1.) the item shrinks and remains attached at the same offset to the mouse (appearing to scale at your mouse point, as if your mouse point were the origin) Things I have tried: 1.) in the onDragPress, I attempted to get the the mouse coordinates within the drag target's container and instantly relocate the item to those coordinates. That results in bazaar behavior. 2.) I've attempted calling myDraggable.update() before and during setting the scalethe scale animation, and onDragMove Any help is appreciated, thanks a lot in advance! Also, let me say: TimelineLite and TweenLite are some of the most incredible libraries I've used. Pushing my company to purchase a member license.
×
×
  • Create New...