我在此链接中尝试了本教程
我的代码是
<!DOCTYPE html>
<html>
<head>
<link href="cropper.css" rel="stylesheet" />
</head>
<body>
<img id="teh" src="image.png" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="cropper.js"></script>
<script>
$("#teh").cropper();
</script>
</body>
</html>
但是,它会在$("#teh").cropper();
时遇到错误Uncaught TypeError: $(...).cropper is not a function
已经找到了解决方案。我需要添加
<script src="jquery-cropper.js"></script>
所以,它变成了
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="cropper.js"></script>
<script src="jquery-cropper.js"></script>
我认为您在支持旧版本的同时正在使用jQuery新版本。
var image = document.getElementById('image');
var cropper = new Cropper(image, {
aspectRatio: 16 / 9,
crop: function(e) {
console.log(e.detail.x);
console.log(e.detail.y);
}
});
<link href="https://cdnjs.cloudflare.com/ajax/libs/cropperjs/0.8.0/cropper.min.css" rel="stylesheet"/>
<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/cropperjs/0.8.0/cropper.min.js"></script>
<img id="image" src="https://lh5.googleusercontent.com/-_nU33sjf1SI/AAAAAAAAAAI/AAAAAAAASgQ/VOkKnOIxP8g/photo.jpg?sz=328" />