This article mainly introduces in detail how to use the jQuery user avatar cropping plug-in cropbox.js. It has certain reference value. Interested friends can refer to it. I hope it can help everyone.
Almost every web page has a must-have image upload and image cropping function. This function is implemented here through the cropbox.js plug-in.
<script src="js/jquery-1.11.1.min.js"></script> <script src="js/cropbox.js"></script> <script type="text/javascript"> $(window).load(function() { var options = { thumbBox: '.thumbBox', spinner: '.spinner', imgSrc: 'images/avatar.png' } var cropper = $('.imageBox').cropbox(options); $('#file').on('change', function(){ var reader = new FileReader(); reader.onload = function(e) { options.imgSrc = e.target.result; cropper = $('.imageBox').cropbox(options); } reader.readAsDataURL(this.files[0]); this.files = []; }) $('#btnCrop').on('click', function(){ var img = cropper.getDataURL(); $('.cropped').append('<img src="'+img+'">'); }) $('#btnZoomIn').on('click', function(){ cropper.zoomIn(); }) $('#btnZoomOut').on('click', function(){ cropper.zoomOut(); }) }); </script>
Related recommendations:
5 latest jQuery images Cropping plug-in
jQuery implements image upload and cropping plug-in Croppie_jquery
The above is the detailed content of jQuery user avatar cropping plug-in cropbox.js example sharing. For more information, please follow other related articles on the PHP Chinese website!