简体   繁体   中英

Uncaught TypeError: $(...).cropper is not a function - cropper.js

I tried the tutorial at this link

My code is

<!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>

But, it hits error Uncaught TypeError: $(...).cropper is not a function at $("#teh").cropper();

Found the solution already. I need to add

<script src="jquery-cropper.js"></script>

so, it becomes

<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>

I think you are using jQuery new version while it is supporting old version.

 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" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM