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

don't work in modal ! #43

Open
AkramZerarka opened this issue Oct 13, 2019 · 1 comment
Open

don't work in modal ! #43

AkramZerarka opened this issue Oct 13, 2019 · 1 comment

Comments

@AkramZerarka
Copy link

When I insert the picture and I resize my window the cropper takes another width and height****

@moqmar
Copy link

moqmar commented Nov 6, 2021

For people finding this thread: the following TypeScript code works for me to dynamically resize the cropper using directly the .croppr-image and .croppr-imageClipped elements.

let lastKnownValue: Croppr.CropValue;
this.uploadedImageCropper = new Croppr(el, {
	// options
	// ...
	// store ratio value on update, needed for resize handling
	returnMode: "ratio",
	onCropEnd(data: Croppr.CropValue) {
		lastKnownValue = { ...data };
	},
	onInitialize(instance: Croppr) {
		// set the maximum height to (100vh - 15rem) to avoid scrolling
		let bounds = instance["imageEl"].getBoundingClientRect();
		instance["imageEl"].style.width = instance["imageClippedEl"].style.width =
			"calc((100vh - 15rem) * " + (Math.floor((bounds.width * 1000) / bounds.height) / 1000).toString() + ")";
		// handle resizing correctly
		lastKnownValue = instance.getValue();
		instance["resizeObserver"] = new ResizeObserver(() => {
			const bounds = instance["imageEl"].getBoundingClientRect();
			instance["box"].move(lastKnownValue.x * bounds.width, lastKnownValue.y * bounds.height);
			instance.resizeTo(lastKnownValue.width * bounds.width, lastKnownValue.height * bounds.height, [0, 0]);
		});
		instance["resizeObserver"].observe(instance["imageEl"]);
	},
});

Maybe that should be integrated directly into the library?

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

2 participants