Jquery local upload preview extension (hidden upload control click Image Upload supports ie !!), Jquery Image Upload

Source: Internet
Author: User

Jquery local upload preview extension (hidden upload control click Image Upload supports ie !!), Jquery Image Upload

Address of raw material I use: http://www.cnblogs.com/leejersey/p/3660202.html

After modification:

/// <Reference path = "../Js/jquery-1.7.2.min.js"/>/** usage :!!!!!!!! Put input above the image <div> <input type = "file" id = "up"/>  </div> set a div out of the IMG tag to be previewed, and give the upload Control id uploadPreview, call CheckInito, and click the image. $ ("# up "). uploadPreview ({Img: "ImgPr", Width: 120, Height: 120, ImgType: ["gif", "jpeg", "jpg", "bmp ", "png"], Callback: function (){}}). checkInito (); var p = $ ("fff "). uploadPreview ({}); p. checkFile () // The "SELECT file" dialog box pops up immediately. The ie option is not suitable */$. fn. exten D ({uploadPreview: function (opts) {var _ self = this, _ this = $ (this); opts = jQuery. extend ({Img: "ImgPr", Width: 100, Height: 100, ImgType: ["gif", "jpeg", "jpg", "bmp ", "png"], Callback: function () {}}, opts ||{}); _ self. getObjectURL = function (file) {var url = null; if (window. createObjectURL! = Undefined) {url = window. createObjectURL (file)} else if (window. URL! = Undefined) {url = window. URL. createObjectURL (file)} else if (window. webkitURL! = Undefined) {url = window. webkitURL. createObjectURL (file)} return url}; _ this. change (function () {if (this. value) {if (! RegExp ("\. ("+ opts. imgType. join ("|") + ") $", "I "). test (this. value. toLowerCase () {alert ("file selection error, image type must be" + opts. imgType. join (",") + "); this. value = ""; return false} var ie = navigator. appName = "Microsoft Internet Explorer "? True: false; if (ie) {try {$ ("#" + opts. img ). attr ('src', _ self. getObjectURL (this. files [0])} catch (e) {var src = ""; var obj = $ ("#" + opts. img); var div = obj. parent ("div") [0]; _ self. select (); if (top! = Self) {your own parent.doc ument. body. focus ()} else {_ self. blur ()} src = document. selection. createRange (). text; document. selection. empty (); obj. hide (); obj. parent ("div" ).css ({'filter': 'progid: DXImageTransform. microsoft. alphaImageLoader (sizingMethod = scale) ', 'width': opts. width + 'px ', 'height': opts. height + 'px '}); div. filters. item ("DXImageTransform. microsoft. alphaImageLoader "). src = src }} Else {$ ("#" + opts. img ). attr ('src', _ self. getObjectURL (this. files [0])} opts. callback ()}) return {/* ie is not applicable! */CheckFile: function CheckFile () {var ie = navigator. appName = "Microsoft Internet Explorer "? True: false; if (ie) {_ this [0]. click ();} else {var mouseobj = document. createEvent ("MouseEvents"); mouseobj. initEvent ("click", true, true); _ this [0]. dispatchEvent (mouseobj);} return _ self;}, // compatible with ie 8 CheckInito: function () {var ie = navigator. appName = "Microsoft Internet Explorer "? True: false; _this.css ("position", "absolute"); _this.parent().css ("width", opts. width + "px"); _this.parent().css ("height", opts. height + "px"); if (ie) {// width: 67.5px; height: 37.4px; padding-right: 5px; position: absolute; opacity: 1; _this.css ("width", opts. width + "px"); _this.css ("height", opts. height + "px"); _this.css ("font-size", "200px"); _this.css ("overflow", "hidden");} else {_this.css ("left ", "0px"); _this.css ("top", "0px"); _this.css ("width", opts. width + "px"); _this.css ("height", opts. height + "px") ;}_this.css ("opacity", "0"); return _ self ;}};}});

Call instance:

 

<!DOCTYPE html>

Final

Ie:

 

Firefox:

 

Google:

 

 

Please provide more support

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.