acornejo / jquery-cropbox

jQuery Cropbox plugin
http://acornejo.github.io/jquery-cropbox/
MIT License
345 stars 82 forks source link

Zoom and update methods ? #53

Open Rqsb opened 10 years ago

Rqsb commented 10 years ago

Hello,

I've been trying to use your zoom() and update() methods in a code snippet but so far it doesn't do anything. What did I get wrong ?

Here's the code snippet I used

$(function () {
    var r = $('#results'),
        x = $('.cropX', r),
        y = $('.cropY', r),
        w = $('.cropW', r),
        h = $('.cropH', r);
    $('#cropimage').cropbox({
        width: 200,
        height: 200
    }).on('cropbox', function (event, results, img) {
        x.text(results.cropX);
        y.text(results.cropY);
        w.text(results.cropW);
        h.text(results.cropH);
    });
    crop = $('#cropimage').data('cropbox');
    crop.zoom(1); // or zoom(0);
    crop.update();
});

Thanks !

Quji commented 10 years ago

There is no onLoad method for now, so u have 2 options:

setTimeout(function() {
    crop = $('#cropimage').data('cropbox');
    crop.zoom(1); // or zoom(0);
    crop.update();
}, 100);

or use one of pull requests: https://github.com/acornejo/jquery-cropbox/pull/56, https://github.com/acornejo/jquery-cropbox/pull/51