Home > Web Front-end > JS Tutorial > jQuery user avatar cropping plug-in cropbox.js example sharing

jQuery user avatar cropping plug-in cropbox.js example sharing

小云云
Release: 2018-01-10 10:28:48
Original
2099 people have browsed it

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: &#39;.thumbBox&#39;,
      spinner: &#39;.spinner&#39;,
      imgSrc: &#39;images/avatar.png&#39;
    }
    var cropper = $(&#39;.imageBox&#39;).cropbox(options);
    $(&#39;#file&#39;).on(&#39;change&#39;, function(){
      var reader = new FileReader();
      reader.onload = function(e) {
        options.imgSrc = e.target.result;
        cropper = $(&#39;.imageBox&#39;).cropbox(options);
      }
      reader.readAsDataURL(this.files[0]);
      this.files = [];
    })
    $(&#39;#btnCrop&#39;).on(&#39;click&#39;, function(){
      var img = cropper.getDataURL();
      $(&#39;.cropped&#39;).append(&#39;<img src="&#39;+img+&#39;">&#39;);
    })
    $(&#39;#btnZoomIn&#39;).on(&#39;click&#39;, function(){
      cropper.zoomIn();
    })
    $(&#39;#btnZoomOut&#39;).on(&#39;click&#39;, function(){
      cropper.zoomOut();
    })
  });
</script>
Copy after login

Related recommendations:

Jquery image cropping plug-in

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template