Guest User

Untitled

a guest
Oct 19th, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 0.66 KB | None | 0 0
  1. (function ($) {
  2.  
  3.     $.fn.imgLoader = function (options) {
  4.  
  5.         var settings = $.extend( {
  6.             'target' : $('.show'),
  7.             'width' : 'auto',
  8.             'height' : 'auto'
  9.         }, options);
  10.  
  11.         this.each(function () {
  12.             $(this).change(function () {
  13.                 var reader = new FileReader();
  14.  
  15.                 // Closure to capture the file information.
  16.                 reader.onload = (function(theFile) {
  17.  
  18.                     return function(e) {
  19.                         settings.target.html('<img src="'+e.target.result+'" width="'+settings.width+'" height="'+settings.height+'" />');
  20.                     };
  21.  
  22.                 })(this.files[0]);
  23.  
  24.                 // Read in the image file as a data URL.
  25.                 reader.readAsDataURL(this.files[0]);
  26.             });
  27.         });
  28.  
  29.     };
  30.  
  31. })(jQuery);
Add Comment
Please, Sign In to add comment