Skip to content
This repository has been archived by the owner on Nov 27, 2018. It is now read-only.

api.zoom() doesn't seem to work for certain values #25

Closed
sugataach opened this issue Mar 1, 2016 · 5 comments
Closed

api.zoom() doesn't seem to work for certain values #25

sugataach opened this issue Mar 1, 2016 · 5 comments
Assignees
Labels

Comments

@sugataach
Copy link

Hey bcabanes,

Great directive!

Just having some trouble with the zoom api, it doesn't seem to work for integers less than 3 (including negative numbers).

Ideally, I'd like to pass in zoom(1) or zoom(-1).

See codepen link, try playing around with the settings on the "Zoom API" button.

Codepen Link

@sugataach
Copy link
Author

Hmmm some interesting findings:

WORKS FOR

api.zoom(1.01)

DOESN'T WORK

api.zoom(1)
api.zoom(2)
api.zoom(-1)
api.zoom(-1.01)
api.zoom(-3)

@sugataach sugataach changed the title api.zoom() doesn't seem to work api.zoom() doesn't seem to work for certain values Mar 1, 2016
@bcabanes bcabanes self-assigned this Mar 1, 2016
@bcabanes bcabanes added the bug label Mar 1, 2016
@bcabanes
Copy link
Owner

bcabanes commented Mar 1, 2016

Hi @sugataa,
It seems like a bug, thank you very much for the Codepen 👍 link it helps a lot. I'll make a bugfix soon. I think api.zoom() isn't a good idea, api.zoomIn() & api.zoomOut() make more sense.

@sugataach
Copy link
Author

Hey, afraid there's still an issue with api.zoomOut, I can't seem to get it to work.

api.zoomOut isn't even registering in the api

Here's a gist of how I ended up "hacking" it...

https://gist.github.com/sugataa/9d7c4986b9ca2071b668

@sugataach
Copy link
Author

Basically I changed api.zoomIn(factor) back to api.zoom(factor)

WORKS

to zoomIN -> factor must be bigger than 1
to zoomOUT -> factor must be less than 1

@jokeMF
Copy link

jokeMF commented Mar 3, 2017

I had the same problem and I found the 'bug': the zoom factor is converted twice resulting in a 2x zoom with values close to 1.

In Cropper.prototype.setDimensions zoomInFactor and zoomOutFactor are set:

this.zoomInFactor = 1 + parseFloat(this.options.zoomStep);
this.zoomOutFactor = 1 / this.zoomInFactor;

then in Cropper.prototype.bindControls applyZoomIn and applyZoomOut are bound:

this.elements.controls.zoomIn.addEventListener('click', function() {
self.applyZoomIn(self.zoomInFactor);
});
this.elements.controls.zoomOut.addEventListener('click', function() {
self.applyZoomOut(self.zoomOutFactor);
});

in these two functions the zoom factor is converted again, causing the factor 2

Cropper.prototype.applyZoomIn = function(zoom) {
this.zoomImage(1 + parseFloat(zoom));
};
Cropper.prototype.applyZoomOut = function(zoom) {
this.zoomImage(1 / ( 1 + parseFloat(zoom)));
};

To make it work properly I replaced both calls by:

this.zoomImage(parseFloat(zoom));

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

No branches or pull requests

3 participants