Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
norach14

Using draggable – need resizable to keep aspect aspect ratio

Recommended Posts

I am using Draggable and ThrowPropsPlugin. I want to have divs (eventually with images) be both draggable and resizable. I have this working, BUT the user can resize the box horizontally and vertically which will stretch or squish the image. How can I set it up so the box (image) gets resized proportionally, keeping the images aspect ratio? I've attached my html file.

 

Thanks,

Caroline

gsap_draggable_test1.html

Link to comment
Share on other sites

Hello norach14, and Welcome to the GreenSock Forum!

 

I am not near my computer right now.

 

But in CSS, to keep an image proportional when its parent gets resized, looks something like this (2 ways):

:

/* #1 - using max-width property to keep img tag proportional when resizing parent */
.image-wrapper > img {
   max-width:100%;
   height:auto;
}

/* or this way */

/* #2 - using max-width property to keep img tag proportional when resizing parent */
.image-wrapper > img {
   width:100%; 
   height:auto;
}

/* or this final way */

/* #3 - using both max-width and width property to keep img tag proportional when resizing parent */
.image-wrapper > img {
    max-width:100%;
    width:100%;
    height:auto;
}:

:

Then when the img tag's parent is resized .. the img will resize it self proportionally,  either using max-width or width.

 

I prefer using max-width myself.

 

I hope this helps :)

  • Like 1
Link to comment
Share on other sites

Hello again norach14,

 

Here is an example from a codepen fork from jamiejefferson called 

See the Pen fjJah by jamiejefferson (@jamiejefferson) on CodePen

. Thanks Jamie :D

 

I modified it to have an image resize aspect ratio with the GSAP Draggable resize. Drag the resize handle to see the image resize:

 

See the Pen LEqLbO by jonathan (@jonathan) on CodePen

 

I hope this helps! :)

  • 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.
×