我正在使用cropperjs,我想创建一个按钮来调用cropperjs中的rotate方法,也就是说,有一个顺时针90度和逆时针90度的按钮。我尝试了下面的代码,但不起作用。
<script>
window.addEventListener('DOMContentLoaded', function () {
var image = document.getElementById('image');
var imgRotate = document.getElementById('rotateImg');
var cropper = new Cropper(image, {
aspectRatio: 20 / 15,
built: function () {
}
});
document.getElementById('rotateImg').onClick = function () {
cropper.rotate(90);
};
});
</script>发布于 2016-04-01 17:54:58
两个步骤:
1)为了确保您的函数被调用,您可以按如下方式跟踪它。
document.getElementById('rotateImg').onClick = function () {
console.log("I'm in, go to step 2");
cropper.rotate(90);
};2)你需要告诉cropper允许你想要使用的功能,这里有一个不同的例子:
cropper = new Cropper(image, {
movable: true,
zoomable: true,
rotatable: true,
scalable: true
});希望这能帮你节省时间。
https://stackoverflow.com/questions/36335022
复制相似问题