Jump to content
Search Community

Using draggable – need resizable to keep aspect aspect ratio

norach14 test
Moderator Tag

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

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