Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Responsive Sizing #76

Closed
wunderdojo opened this issue Mar 11, 2018 · 4 comments
Closed

Responsive Sizing #76

wunderdojo opened this issue Mar 11, 2018 · 4 comments

Comments

@wunderdojo
Copy link

wunderdojo commented Mar 11, 2018

Thanks a ton for your library, it was exactly what I needed for a project and works beautifully. One thing I ran into -- and I might just be missing an option or something -- is that the width and height only take pixel values, not percentages. I'm opening croppa in a modal window and depending on the screen size I need it to adjust accordingly. In other words, if someone is using it on a phone it needs to be much smaller than if they're on a large monitor.

What I've done for now is used a method that sets the width and height dynamically when the modal is opened. In this example I want a 1:1 aspect ratio so I use the same value for width and height:

var width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;

this.croppaWidthHeight = ( width < 600 ) ?  width * .6 : width * .3;

I could use a series of if / else statements to adjust for various breakpoints but this works for my current use case. Is there a better way of making it responsive?

@zhanziyang
Copy link
Owner

Currently the only way is to set it dynamically like what you did. I will improve this very soon.

So what we need is let croppa automatically adjust its size to fit a container whose size can be controlled with CSS. Is that right? So that you can make it responsive just like how you make a normal block element responsive.

@wunderdojo
Copy link
Author

That would be ideal.

@zhanziyang
Copy link
Owner

@wunderdojo Checkout new version 1.3.0. With the new prop auto-sizing set to true, croppa automatically adjust itself to its container div's size.

DEMO: https://codepen.io/zhanziyang/pen/bvVKzL

@evrenbal
Copy link

evrenbal commented Feb 6, 2020

@wunderdojo Checkout new version 1.3.0. With the new prop auto-sizing set to true, croppa automatically adjust itself to its container div's size.

DEMO: https://codepen.io/zhanziyang/pen/bvVKzL

Thank you for the update, however it doesn't work as expected when the parents box-sizing is set to border-box and has a border. (Especially if it has a thick border)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants