question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Responsive viewport and boundary

See original GitHub issue

Hello everyone, I have one question is there any solution to redraw/reset the croppie boundary and viewport on window resize I tried something like this for tracking and setting new value:

var bwidth;

  $(window).resize(function(){
     cwidth = $(window).width();

     if( cwidth <= 480 && cwidth >= 320) {
       bwidth = cwidth - 40;
     } else {
       bwidth = 185;
     }
     });

and here is the config code:

$uploadCrop = $('#uploaded-picture').croppie({
     enableExif: true,
     viewport: {
       width: 220,
       height: 330
     },
     boundary: {
       width: bwidth,
       height: 411
     },
       enableOrientation: true
});

I only get the croppie container with 185px width.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
Xstyler85commented, Aug 28, 2021

I found simpler solution. Just re-bind values on the window resize to force croppie to re-calculate values like this:

window.onresize = () => {
     croppie.bind({
          url: image,
          points: points,
          orientation: orientation,
          zoom: zoom
     })
}
1reaction
nicholascouragecommented, Jun 25, 2020

I spent a few hours trying to solve this. Making it responsive in bootstrap on an Iphone5 for example meant that any static values would overlap the screen. As I’m trying to maintain an aspect ratio (2:1 i.e. a rectangle) and maintain the margin appearance of the boundary over the viewport, I’ve set the enableResize option to false. My problem had the added complexity of this rendering in a bootstrap modal but got I there with this:

$("#file-upload").on("change", function(event) {

    $("#myModal").modal();

    // Initailize croppie instance and assign it to global variable

    var boundaryWidth = $(".modal-body").width();

    var boundaryHeight = boundaryWidth / 2;   

    var viewportWidth = boundaryWidth - (boundaryWidth/100*25);

    var viewportHeight = boundaryHeight - (boundaryHeight/100*25);

    croppie = new Croppie(el, {

        viewport: { width: viewportWidth, height: viewportHeight },
        boundary: { width: boundaryWidth, height: boundaryHeight },
        enableOrientation: true,

    });

    $.getImage(event.target, croppie); 

});

With this, what ever the size of my bootstrap modal, croppie’s dimensions are then set dynamically. The only problem I’ve got with this is that if the browser’s viewport is resized after this is executed then croppie’s width and height settings aren’t updated but guess this is easily solved with some change event, etc.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Responsive Web Design Viewport - W3Schools
The viewport is the user's visible area of a web page. The viewport varies with the device, and will be smaller on a...
Read more >
Responsive web design basics
Responsive web design basics ; Set the viewport. Ensure an accessible viewport ; Size content to the viewport. Images; Layout ; Use CSS...
Read more >
Viewport concepts - CSS: Cascading Style Sheets | MDN
Any sub-viewport that is fully or partially displayed within the layout viewport is considered a visual viewport. We generally think of width ...
Read more >
Viewport-relative, fluid, responsive web design
Learn how to build a viewport-relative, fluid, responsive web design using CSS. Information on the pros and cons of such a web design ......
Read more >
Viewports and Media Queries - LearnHowToProgram.com
Also, keep in mind this week will focus only on implementing the media query code that make a site responsive. We won't explore...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found