Jump to content
Search Community

Resizing object with draggable, scale value adds resistance!

Pilatus test
Moderator Tag

Go to solution Solved by GreenSock,

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

Hello,

 

I am implementing a basic resizeable object which works perfectly (without using scaling).

When I add some scaling to the resizing object then I feel drag resistance when resizing.

The resistance happens when I resize, not when I drag the box, also the object top left moves leftward and does not fully enlarge or shrink following the mouse.

Do you have any idea on how to correct for the scaling factor so that the resize handle nicely follows the mouse?

I think this problem is similar to http://greensock.com/forums/topic/9279-draggable-with-css-scaling/ but I couldn't really figure out the fix.

$(document).ready(function(){
  var drag = $("#draggable");
  var handle = $("<div class='resize-handle'></div>").appendTo(drag);
  TweenLite.set(drag, {scale: 2}); // <<--- this adds resistance <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  TweenLite.set(handle, {top: drag.width(), left: drag.height()});
  
  var dragInst;
  dragInst = Draggable.create(drag, {
        bounds: "body",
        edgeResistance: 0.85
      });
  
  var arrowdragInst;
  arrowdragInst = Draggable.create(handle, {
    type:"top,left",
    edgeResistance: 0.85,
    
    onPress: function(e) {
      e.stopPropagation(); // cancel drag    
      /*console.log("$(this.target).position().left = " + $(this.target).offset().left);
      console.log("$('body').width() = " + $("body").width());
      console.log($("body").width() - $(this.target).offset().left);*/
      this.applyBounds({top:100, left:100, width: ($("body").width() - $(this.target).offset().left + (this.x - 60)),
                        height: ($("body").height() - $(this.target).offset().top) +  + (this.y - 60)});
    },
    onDrag: function(e) {
      TweenLite.set(this.target.parentNode, { width: this.x, height: this.y });
    }
  });  
      
  $("body").on("mouseleave", function(e) {
    console.log("mouseleave body");
    dragInst[0].endDrag(e);
    arrowdragInst[0].endDrag(e);
  });
    
});

See the Pen xGOaeX by anon (@anon) on CodePen

Link to comment
Share on other sites

  • Solution

It looks like the main problem is that you've got your transform using the default origin (center), but your resizing/dragging logic is assuming top left. So try adding transformOrigin:"left top" to your scale tween/set:

TweenLite.set(drag, {scale: 2, transformOrigin:"top left"});

Is that what you're looking for? 

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...