| <! DOCTYPE html> <Html> <Head> <Title> TODO supply a title </title> <Meta charset = "UTF-8"> <Meta name = "viewport" content = "width = device-width"> <Script src = "./jquery. min. js"> </script> <Script src = "./jcrop/jquery. Jcrop. min. js"> </script> <Link href = "./jcrop/jquery.Jcrop.min.css" rel = "stylesheet"> </Head> <Style> . Upload-btn { Width: 130px; Height: 25px; Overflow: hidden; Position: relative; Border: 3px solid # 06c; Border-radius: 5px; Background: # 0cf; } . Upload-btn: hover { Background: # 09f; } . Upload-btn _ txt { Z-index: 1; Position: relative; Color: # fff; Font-size: 18px; Font-family: "Helvetica Neue "; Line-height: 24px; Text-align: center; Text-shadow: 0 1px 1px #000; } . Upload-btn input { Top:-10px; Right:-40px; Z-index: 2; Position: absolute; Cursor: pointer; Opacity: 0; Filter: alpha (opacity = 0 ); Font-size: 50px; } </Style> <Body> <Div> <! -- "Js-fileapi-wrapper" -- required class --> <Div class = "js-fileapi-wrapper upload-btn" id = "choose"> <Input name = "files" type = "file" multiple/> <Button id = "btn"> upload </button> </Div> <Div id = "images"> <P style = "margin-top: 40px;"> </p> <Div id = "img2"> </div> <Div id = "img3"> </div> </Div> </Div> <Script> window. FileAPI = {staticPath: './fileapi/'}; </script> <Script src = "./fileapi/FileAPI. min. js"> </script> <Script> Var el = $ ('input'). get (0 ); FileAPI. event. on (el, 'change', function (evt ){ Var files = FileAPI. getFiles (evt); // Retrieve file list FileAPI. filterFiles (files, function (file, info ){ If (! /^ Image/. test (file. type )){ Alert ('incorrect image format '); Return false; } Else if (file. size> 20 * FileAPI. MB ){ Alert ('image must be smaller than 20m '); Return false; } Else { Return true; } }, Function (files, rejected ){ If (files. length ){ Var file = files [0]; Var img0 = FileAPI. Image (file ); Var img1 = FileAPI. Image (file ); Var ratio = 0; FileAPI. getInfo (file, function (err, info) {// get image ratio If (! Err ){ If (info. width> info. height ){ Ratio = info. width/500; } Else { Ratio = info. height/500; } } }); Img0.resize (500,500, 'max ') // place image and register jcrop . Get (function (err, img ){ $ ('# Img2'). empty (); $ ('# Img2'). append ($ (img )); $ ('# Img2'). children (). Jcrop ({ AspectRatio: 1, BgColor: 'rgba (0,0, 0, 0.4 )', OnSelect: function (c ){ Img1.matrix. sx = c. x * ratio; Img1.matrix. sy = c. y * ratio; Img1.matrix. sw = c. w * ratio; Img1.matrix. sh = c. h * ratio; Img1.matrix. dwx = 500; Img1.matrix. dh = 500; Img1.get (function (err, img ){ // $ ('# Img3'). empty (); // $ ('# Img3'). append ($ (img )); ('{Img3'{.html ($ (img )); }); } }); }); $ ('# Btn'). on ('click', function (){ FileAPI. upload ({ Url: '/testUpFile/upfile ', Files: {images: img1 }, SS: function (evt ){/*...*/}, Complete: function (err, xhr ){/*...*/ // Alert (xhr. responseText ); } }); }); } }); }); </Script> </Body> </Html> |