admin管理员组文章数量:1382502
I'm using a crop tool from fengyuanchen, which has awesome features. I'm trying to make a fixed crop-box with dynamic sizes.
But I'm currently stuck just on how to figger out how to make it a certain size.
I've tried the following:
$(function() {
$('.img-container > img').cropper({
aspectRatio: 16 / 9,
autoCropArea: 0.65,
strict: false,
guides: false,
highlight: false,
dragCrop: false,
cropBoxMovable: false,
cropBoxResizable: false,
setCropBoxData('1600', '1200')
});
});
But setCropBoxData
doesn't work for me. What am I doing wrong?
UPDATE
This should be the correct syntax to set up a fixed width for that actual cropbox, but I still don't get any results:
$(function() {
var $toCrop = $('.img-container > img');
$toCrop.cropper({
aspectRatio: 16 / 9,
autoCropArea: true,
strict: false,
guides: false,
highlight: true,
dragCrop: false,
cropBoxMovable: false,
cropBoxResizable: false,
built: function () {
$toCrop.cropper("setCropBoxData", { width: "100", height: "50" });
}
});
});
I'm using a crop tool from fengyuanchen, which has awesome features. I'm trying to make a fixed crop-box with dynamic sizes.
But I'm currently stuck just on how to figger out how to make it a certain size.
I've tried the following:
$(function() {
$('.img-container > img').cropper({
aspectRatio: 16 / 9,
autoCropArea: 0.65,
strict: false,
guides: false,
highlight: false,
dragCrop: false,
cropBoxMovable: false,
cropBoxResizable: false,
setCropBoxData('1600', '1200')
});
});
But setCropBoxData
doesn't work for me. What am I doing wrong?
UPDATE
This should be the correct syntax to set up a fixed width for that actual cropbox, but I still don't get any results:
$(function() {
var $toCrop = $('.img-container > img');
$toCrop.cropper({
aspectRatio: 16 / 9,
autoCropArea: true,
strict: false,
guides: false,
highlight: true,
dragCrop: false,
cropBoxMovable: false,
cropBoxResizable: false,
built: function () {
$toCrop.cropper("setCropBoxData", { width: "100", height: "50" });
}
});
});
Share
Improve this question
edited Feb 12, 2018 at 8:16
Jeroen Bellemans
asked Jul 14, 2015 at 13:09
Jeroen BellemansJeroen Bellemans
2,0352 gold badges28 silver badges43 bronze badges
1
- 1 Check your browser console: the code you posted is syntactically incorrect, and you'll see an error. – Pointy Commented Jul 14, 2015 at 13:12
2 Answers
Reset to default 5I've finally found the solution. My mistake was that I was passing string
instead of number
as parameters to setCropBoxData
function.
Here is the correct syntax:
$(function() {
var $toCrop = $('.img-container > img');
$toCrop.cropper({
aspectRatio: 16 / 9,
autoCropArea: 0,
strict: false,
guides: false,
highlight: true,
dragCrop: false,
cropBoxMovable: false,
cropBoxResizable: false,
built: function () {
// Width and Height params are number types instead of string
$toCrop.cropper("setCropBoxData", { width: 1600, height: 800 });
}
});
});
Go back and re-read the "Methods" section of the documentation. That shows you how to invoke functions like that. Also note that "setCropBoxData" expects an object with "top", "left", "width", and "height" properties:
$(function() {
var $img = $('.img-container > img');
$img.cropper({
aspectRatio: 16 / 9,
autoCropArea: 0.65,
strict: false,
guides: false,
highlight: false,
dragCrop: false,
cropBoxMovable: false,
cropBoxResizable: false
});
$img.cropper("setCropBoxData", { width: "1600", height: "1200" });
});
本文标签:
版权声明:本文标题:javascript - fengyuanchen cropper how to set up dynamic fixed crop box - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743959984a2568843.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论