本文实例讲述了html5版canvas自由拼图的实现方法。分享给大家供大家参考。具体方法如下:/ r: T7 }7 e/ K; k
代码运行效果如下图所示:
2 T/ E F z/ p, h+ F% Z
7 J& }& w& X: o; P, d4 `7 dcanvaselement.js代码如下:
- z1 V* d; @# h! k8 v$ \; a复制代码代码如下:define('canvaselement', [ '../multi_upload/core' ], function(s) {# `0 u6 { ]$ ~* s: U1 B5 n" y4 x
var canvas = window.canvas || {};
; X0 ~$ |( ` T# g" A* Q0 f(function () {
. d0 N _4 w3 B2 Y7 O$ fcanvas.element = function() {};
+ {3 T5 ?$ o f3 Zcanvas.element.prototype.fillbackground = true;
: w: o- z9 A0 z" V( Ncanvas.element.prototype.showcorners = false;
- N% P: G2 }; {( \4 H: ^3 M, ]2 Tcanvas.element.prototype.photoborder = true;* X4 U, g- ]& J9 o4 T y
canvas.element.prototype.polaroid = false;
: v) d! J0 W+ p! Gcanvas.element.prototype._backgroundimg = null;
: e1 T! b9 h; h& V! y3 c9 z3 N8 Xcanvas.element.prototype._groupselector = null;
% Z/ {+ z/ a9 h( H/ c: x1 d% g4 Dcanvas.element.prototype._aimages = null;
( K$ r; _. w, q8 x: Wcanvas.element.prototype._ocontext = null;: n; d7 I5 J. ] E) p& R* c6 c
canvas.element.prototype._oelement = null;
. k1 m4 l9 G, v# E# P" L3 _' w; ocanvas.element.prototype._oconfig = null;0 @' x7 w' J8 _/ `
canvas.element.prototype._currenttransform = null;7 {, {9 q/ ?7 ?3 K1 p+ _5 ^ v8 c
canvas.element.prototype._prevtransform = null;
; V8 ]. r2 O# U. T" I' Dcanvas.element.prototype.curangle = null;: T' p: y I" |! K/ r
canvas.element.prototype.init = function(el, oconfig) {
- Z: C/ ~( a" Y, v- I4 a) C6 `if (el == '') {0 ? t$ n# t( Z+ l2 w$ j
return;; {# l. v4 v) J( @$ G9 Z' q7 n
}; L, p9 @0 K' g- t# x
this._initelement(el);/ j2 e$ d3 ]6 O! K7 G: Z
this._initconfig(oconfig);
) W* _- g- }, ^! _% othis._createcanvasbackground();
) i, B: i' H+ G1 w9 }this._createcontainer();
" ~- a# r. P- ^( x+ X- I7 ythis._initevents();9 P0 r, d7 [1 G
this._initcustomevents();1 X* v9 K! Z5 H0 A# p4 Q
};" a0 C' T0 M1 Y" ?+ W+ a0 j
canvas.element.prototype._initelement = function(el) {
8 Q2 E+ l$ ~# y, R: wthis._oelement = document.getelementbyid(el);8 B9 m; R% u( T3 C0 Y7 z. k- S- I
this._ocontexttop = this._oelement.getcontext('2d');
8 u6 Q7 k* M3 x' w" x+ [2 ?};
/ i0 z* \; U# k ~6 Q$ bcanvas.element.prototype._initcustomevents = function() {
- ]2 ^( S2 P; A' [! E6 ?. _this.onrotatestart = new canvas.customevent('onrotatestart');# F$ P0 r4 _& ^( J$ M/ m& X% u
this.onrotatemove = new canvas.customevent('onrotatemove');
+ W1 Y' C9 N+ S' z4 [! U k4 wthis.onrotatecomplete = new canvas.customevent('onrotatecomplete');6 U% D, h4 y# D5 o0 p& P
this.ondragstart = new canvas.customevent('ondragstart'); $ `4 }; T* s( _2 L6 e( o4 K& a1 \
this.ondragmove = new canvas.customevent('ondragmove');5 a2 i7 Y* |5 W$ i
this.ondragcomplete = new canvas.customevent('ondragcomplete');
+ P7 ]# \" d( S( q$ C};! ~9 P+ [& r% I5 p7 V$ `
canvas.element.prototype._initconfig = function(oconfig) {
2 R5 T5 F# }* x u( H: jthis._oconfig = oconfig;5 I: O( B7 S* \" f
this._oelement.width = this._oconfig.width;
5 g! B" J" Y5 Sthis._oelement.height = this._oconfig.height;+ u6 [/ _! l E
this._oelement.style.width = this._oconfig.width + 'px';; T8 Z. p0 J4 i2 E9 N6 r
this._oelement.style.height = this._oconfig.height + 'px';2 ]+ m/ U& w, \( X# l
};- j0 y- x# Z6 M, _7 X! w
canvas.element.prototype._initevents = function() {) h" x- C! n+ c3 G
var _this=this;
8 X) x! A! U# i. G0 ks(this._oelement).on('mousedown',function(e){
0 J) S0 O7 R' s1 K' F9 h# v& B( w_this.onmousedown(e);) J5 q8 @2 v. {( u Z- s% a8 L
});
% ~) i0 P9 l) P# d% o) S5 Es(this._oelement).on( 'mouseup', function(e){5 z. m0 @1 C/ A0 i- {/ ]
_this.onmouseup(e);
5 G" X% c3 J' B});
" ?$ R6 v9 Z1 h. V6 ps(this._oelement).on('mousemove', function(e){$ z. s; _' p+ ^7 c# A* B: b4 f: }* R
_this.onmousemove(e);6 a* \, L0 A5 \' G! K3 Q: G! A
});4 a( I+ B# R1 Z& D& ~
};
7 D' U& ^7 G$ F8 m$ ~) N5 ~. L$ Hcanvas.element.prototype._createcontainer = function() {
) a: E9 W `# z: z6 mvar canvasel = document.createelement('canvas');
- Z& f U) |2 O# y% V1 Wcanvasel.id = this._oelement.id + '-canvas-container';
3 N# C8 ?: \7 E* Jvar ocontainer = this._oelement.parentnode.insertbefore(canvasel, this._oelement);( M7 P3 O! \& F I1 g$ N, w- z
ocontainer.width = this._oconfig.width;& p4 c/ L% ~4 E
ocontainer.height = this._oconfig.height;0 X$ B# L: q% E6 ^8 M6 k& |) H
ocontainer.style.width = this._oconfig.width + 'px';5 B0 Y0 R" a. o8 k
ocontainer.style.height = this._oconfig.height + 'px';7 G: u7 S- k3 ]% U( A8 _
this._ocontextcontainer = ocontainer.getcontext('2d'); $ x, @7 J' `& S* n/ g: n
};9 j1 u- ?$ a& @( T
canvas.element.prototype._createcanvasbackground = function() {
/ [) l/ S# ]- a9 s2 [# ^1 \. ]var canvasel = document.createelement('canvas');
" \2 n$ d! ~6 |& x+ _. @3 e) \canvasel.id = this._oelement.id + '-canvas-background';2 m' h1 @# { X& r: S
var obackground = this._oelement.parentnode.insertbefore(canvasel, this._oelement); e% |& P: D- \6 @- I& S
obackground.width = this._oconfig.width;
7 ]+ f0 ]% _# w' T H7 Q4 l! lobackground.height = this._oconfig.height;9 v* B1 A3 D: N1 H: [1 U7 [+ S. D! _
obackground.style.width = this._oconfig.width + 'px';
7 O5 M" q! {+ p4 _obackground.style.height = this._oconfig.height + 'px';
" q* {& h& f! b8 Cthis._ocontextbackground = obackground.getcontext('2d'); * J6 z C+ a, K; t. q0 i
};
! B& ~# P6 n; b) f9 ocanvas.element.prototype.setcanvasbackground = function(oimg) {
* G3 ^7 e! l/ `- O; q* y, sthis._backgroundimg = oimg;
" n( o5 o. g/ {6 N) Q3 W8 Nvar originalimgsize = oimg.getoriginalsize();
- ]- s9 t" H3 W8 L! wthis._ocontextbackground.drawimage(oimg._oelement, 0, 0, originalimgsize.width, originalimgsize.height);
* F! X- B( v9 R( |* r0 H5 f};4 E) K3 N- B3 h
canvas.element.prototype.onmouseup = function(e) {
7 b k0 E% X; G8 j; p2 h5 Rif (this._aimages == null) {
9 D' V) J( @3 A4 V+ [return;- N! w3 q# r. e) Z
}
& G4 l# b- f0 M; {2 Uif (this._currenttransform) {
7 f: x" m- a. _this._currenttransform.target.setimagecoords(); D/ W8 ^/ a7 D' L5 F8 J
}4 B7 H" }( D# O, z
if (this._currenttransform != null && this._currenttransform.action == rotate) {
/ L4 c! m/ O) P" y2 d2 D( dthis.onrotatecomplete.fire(e);
$ ~; Q: `/ I7 F9 H! F2 K} else if (this._currenttransform != null && this._currenttransform.action == drag) {* c/ ]$ Z" O1 A* N& H6 q o
this.ondragcomplete.fire(e);' P" m; K' w7 c4 s( j7 q( D
}/ D1 w B( w6 e
this._currenttransform = null;' r/ O! c) d" G+ r5 H3 ^ C0 u
this._groupselector = null;
( i- b% R" v- T0 nthis.rendertop();% D6 S* z k* @$ o6 M
};
! U: \( o8 W( V g- a D" dcanvas.element.prototype.onmousedown = function(e) {
2 X2 y- R2 @1 z1 ~8 G: @var mp = this.findmouseposition(e);* T3 W4 V, L! i9 B5 h/ E V
if (this._currenttransform != null || this._aimages == null) {
! ?- T( s. e% Y7 Z% J3 @return;
. }& S$ \" O7 V7 n& ~0 e9 L}
8 t6 p* i* ]0 f; X7 ]4 j3 K6 `% Wvar oimg = this.findtargetimage(mp, false);
/ s9 P: t- S( z+ Yif (!oimg) {# @5 r# P) @2 S6 `5 |
this._groupselector = { ex: mp.ex, ey: mp.ey,
" ~! h" \' A4 u! Gtop: 0, left: 0 };
# U9 D: x F6 X; ~" p}: |% ?, t1 z/ C4 } p! m$ j
else {
# G/ w3 B3 ]9 H0 V* x" n0 Uvar action = (!this.findtargetcorner(mp, oimg)) ? 'drag' : 'rotate';9 x4 o t# ]$ Z" c* T5 i
if (action == rotate) {3 @4 t+ H9 u) N0 E
this.onrotatemove.fire(e);
# U* J4 `) B- a3 g3 c- K* l6 K) Z: r} else if (action == drag) {
: Y. D1 x, I4 K( r( E. Gthis.ondragmove.fire(e);" I; v$ D$ @; H7 `1 k( _
}% S0 W+ i& _, q( k8 Q
this._prevtransform=this._currenttransform = {
( Q* [0 ]* k# l4 jtarget: oimg,
' m: i, h; \) y% L6 {5 p9 T# w3 caction: action,
. K1 a- a* D# Y0 iscalex: oimg.scalex,
' k9 |+ a7 _+ s0 l# s' @% N$ _offsetx: mp.ex - oimg.left,
: d5 H5 o9 e) a1 [offsety: mp.ey - oimg.top,
9 z4 D% w' q# |$ q( qex: mp.ex, ey: mp.ey,
1 _, K- ]- o. H3 C$ r$ }. ~/ Mleft: oimg.left, top: oimg.top,0 h" V) ~/ p5 A5 x( }, ]
theta: oimg.theta
% N) B: {/ f( r: i};
* v3 I+ y* H$ I/ O1 S$('canvas_menu').style.transform='rotate('+oimg.theta*180/3.14+'deg)';, z8 y8 Y6 i" N8 @5 w0 b
$('canvas_menu').style.left=oimg.left+px;
! `( _3 I( F) A2 U) M" |$('canvas_menu').style.top=oimg.top+px;
: W3 J1 i% l5 L/ E! e4 U; S! e$('canvas_menu').style.display=block; X ^7 o% X0 o$ C6 D0 z
this.renderall(false,false);
6 _( G: Y3 ?0 C" p; w; M}; f& [( I& v7 _
};, M+ r$ ^% f. Q6 K
canvas.element.prototype.onmousemove = function(e) {
+ W' H8 T- a8 T$ W* l: |) c( Cvar mp = this.findmouseposition(e);
7 u6 X8 R7 c& `/ u, ^' I4 [if (this._aimages == null) {8 L7 N4 b' U0 y/ M( W, ?
return;
# a) a* M( j- K) l}
$ L% t) \- m1 u! D# ~if (this._groupselector != null) {
! Z& J; e* ]8 a, k9 Athis._groupselector.left = mp.ex - this._groupselector.ex;
% q; b; @1 Z. x8 n! C. \ s2 Jthis._groupselector.top = mp.ey - this._groupselector.ey;
5 v0 M7 P' x! A4 p. D5 y" |this.rendertop();! Q' P) r: M/ S7 o! q8 v$ G
}
, J" g3 k; F' b% L& delse if (this._currenttransform == null) {
$ E) }5 B) g0 q! e% M# _var targetimg = this.findtargetimage(mp, true);9 j9 M9 d1 [$ P [ X
this.setcursor(mp, targetimg);
8 Z& ?; Y" w* d$ I ?" P}3 _$ ^0 K+ o/ L7 z: N
else {/ o6 C' g7 `( P+ S
if (this._currenttransform.action == 'rotate') {7 ~% z7 F0 U0 n) @5 b9 ~9 N
this.rotateimage(mp);3 F- S% c1 ]4 q) P( t& u* ~$ \
this.scaleimage(mp);1 s9 }( C- Y" I, p B/ D
this.onrotatemove.fire(e);
$ I) O1 L" g$ `: v}
( a' ?5 h6 \" L, Melse {
' J6 t4 C$ z. [) ]. P4 J. g2 vthis.translateimage(mp);6 w( V; g1 f. o" ]+ G; p Y
this.ondragmove.fire(e);
" x7 f' j7 T b- t; o}9 I1 G6 M- G, e/ t3 A
this.rendertop();
3 Z0 T* a$ w: I7 a& h9 k; x}
3 _( a4 U2 f* G};+ \. v8 f2 g& s+ |; G
canvas.element.prototype.translateimage = function(mp) {3 R5 i/ d* C9 h$ B
this._currenttransform.target.left = mp.ex - this._currenttransform.offsetx;1 b1 @8 |. M6 v o- J
this._currenttransform.target.top = mp.ey - this._currenttransform.offsety;
) Q' _% q, c6 U- q8 t( _1 n& _, x$('canvas_menu').style.left=this._currenttransform.target.left+px;% x/ j* J/ a7 j
$('canvas_menu').style.top=this._currenttransform.target.top +px;
" ^) h! B) Q7 \' N};
* a3 X7 O8 X7 B4 X! \canvas.element.prototype.scaleimage = function(mp) {+ ]$ F5 v" a+ }9 C1 P9 F
var lastlen = - h$ c1 f9 j' M( k. L
math.sqrt(math.pow(this._currenttransform.ey - this._currenttransform.top, 2) +! j. ~6 }9 N/ g
math.pow(this._currenttransform.ex - this._currenttransform.left, 2));" d" t1 n6 E2 x3 I$ D. [& v) A; z
var curlen = - r' ^" \- }% ?: R6 d) i m
math.sqrt(math.pow(mp.ey - this._currenttransform.top, 2) +
8 w6 Q5 Y. }0 D, V7 p* z [math.pow(mp.ex - this._currenttransform.left, 2));
. E: |- p/ g. V2 A/ D- {var curscalex= this._currenttransform.scalex * (curlen / lastlen);" e9 Z% i W+ m$ n
var curscaley=this._currenttransform.target.scalex;9 i E; L4 I( W) f2 G# {! g H
if(curscalex>0.7&&curscaley>0.7){
# S3 R: W* K1 } W3 X6 l- d/ Kthis._currenttransform.target.scalex =curscalex;
' ]4 G" \; S1 T b# ^6 }/ n2 Ethis._currenttransform.target.scaley = curscaley;! C% G5 L* ~- Y9 d! s; k8 [" d
}
+ d0 w/ P! H6 r, U4 X* ^$ g4 t, v};
2 l1 N) ?' n- J1 {* x9 wcanvas.element.prototype.rotateimage = function(mp) {4 u7 `+ p b( ~3 x1 t! y
var lastangle = math.atan2(# Z g6 G3 _7 F$ P& [* \
this._currenttransform.ey - this._currenttransform.top,
; n5 Z1 z: d; Nthis._currenttransform.ex - this._currenttransform.left
# `& P" t% O$ q6 c: W& G);
# \% C: P7 E4 S: V9 `var curangle = math.atan2(1 U6 @$ W& Q! G4 e( b5 Y$ ~
mp.ey - this._currenttransform.top," \6 D8 \; l! V; r! ?9 g
mp.ex - this._currenttransform.left9 x% V. z6 [& n4 ]
);: A* Z. a. u5 ?: x
this._currenttransform.target.theta = (curangle - lastangle) + this._currenttransform.theta;
! F. O# `; w8 }5 e* i9 s' L( `2 Pthis.curangle=this._currenttransform.target.theta*180/3.14;
" ^' p9 y, @7 S) L6 Y- n$('canvas_menu').style.transform='rotate('+this.curangle+'deg)';
1 c& @* v/ {0 \8 m% J};
( ^3 Q5 }2 g5 R% m$ X" e2 Y0 T3 fcanvas.element.prototype.setcursor = function(mp, targetimg) {
) H( a: x5 y% R. s( X nif (!targetimg) {
5 h& H9 [0 m& F. @) _$ Kthis._oelement.style.cursor = 'default';
. I: [" ]; g. s8 w+ m7 n! s7 \}5 v Z. @6 e/ J3 X8 Z# R
else {
- v0 d- l6 A0 O& {0 G4 Pvar corner = this.findtargetcorner(mp, targetimg);
: J1 h3 D8 C3 y2 Eif (!corner) ( v& j, f; p) O3 K; I
{, x0 n' h. }4 F5 g' g: p
this._oelement.style.cursor = 'default';
/ j& { f, u8 x}
7 p# e( d/ \" C4 k5 [7 Telse: v' x+ q* P( {; B4 A& a8 U
{
7 v: K0 ?; K6 ]' ]8 Mif(corner == 'tr') {
3 d7 D7 Y: \" Q( [' ` B. G' Dthis._oelement.style.cursor = 'ne-resize';
/ H; d5 l. s+ h e2 Q+ G' O}6 Z0 P. h4 f1 y7 A' P2 Z
else if(corner == 'br') {3 s8 ~" T+ |( B, U `3 k- f
this._oelement.style.cursor = 'se-resize';" ~. T9 W" F3 K: N
}- _! O. x. c& l+ v: P6 c
else if(corner == 'bl') {- T& L- H# f3 h# r
this._oelement.style.cursor = 'sw-resize';1 ^1 U7 t: t/ {" X
}! \. z; t8 C! B) O' o: a
else if(corner == 'tl') {) {6 }6 k; _1 m8 D. b; n3 @
this._oelement.style.cursor = 'nw-resize';
4 y: R X. B1 T- G}
D( P# L' u X. Velse {
5 s. i- g) D, E: ithis._oelement.style.cursor = 'default';
/ u) N0 [, L1 K}
' {/ m" b3 r' D, c0 j}3 E$ r3 R. i4 @6 u# U
}' m# f* D+ z u3 O( C5 ?. f& f: z
}; T3 Q$ M5 M; Y
canvas.element.prototype.addimage = function(oimg) {
! s- Z. @" t! O) u% A$ Lif(s.isemptyobject(this._aimages)) {
* A+ `; L% A, e1 A* p/ W Kthis._aimages = [];0 V; w' `8 D! b" I5 Y* a
}, ?& _) X3 F* U+ G2 H+ y1 A
this._aimages.push(oimg);, P3 A, k+ V, R* m
this.renderall(false,true);</p> <p> };
% b8 i; |5 [) _; H2 mcanvas.element.prototype.renderall = function(allontop,allowcorners) {
9 t X8 S; p2 n2 V" W ~) t& `var containercanvas = (allontop) ? this._ocontexttop : this._ocontextcontainer;2 ]$ x4 |. N' ?2 L. `: B8 l l
this._ocontexttop.clearrect(0,0,parseint(this._oconfig.width), parseint(this._oconfig.height));6 N, s2 Z/ ]% _1 L4 F
containercanvas.clearrect(0,0,parseint(this._oconfig.width), parseint(this._oconfig.height));
, C4 T! I; U% v& G' g& v( E7 [6 _if (allontop) {- H! C a- O1 G9 X' @
var originalimgsize = this._backgroundimg.getoriginalsize();) ~) k, x+ s) | w; a* {7 r
this._ocontexttop.drawimage(this._backgroundimg._oelement, 0, 0, originalimgsize.width, originalimgsize.height);1 U5 ~7 J) N7 g$ a- p9 \
}7 X2 m$ k( Q+ d, I; N, ~
for (var i = 0, l = this._aimages.length-1; i < l; i += 1) {4 R3 y; K7 Q u; N5 P; G
this.drawimageelement(containercanvas, this._aimages,allowcorners);
$ x: p1 S I% H, ^( J}" T# M& w$ I5 i8 m
this.drawimageelement(this._ocontexttop, this._aimages[this._aimages.length-1],allowcorners);- N+ }8 ?7 w5 |1 b7 a0 P2 S- N
};
$ X2 L$ D, V' K7 S! ^canvas.element.prototype.rendertop = function() {
( y$ r k2 l, [' Y6 e5 ~ u! pthis._ocontexttop.clearrect(0,0,parseint(this._oconfig.width), parseint(this._oconfig.height));
- P1 L1 J& \, r' \8 Q Sthis.drawimageelement(this._ocontexttop, this._aimages[this._aimages.length-1],true);1 k$ R2 E; k3 F F- L9 h. W# Y
if (this._groupselector != null) {
/ O& C1 C$ B7 ithis._ocontexttop.fillstyle = rgba(0, 0, 200, 0.5);
( m# i% C1 u# zthis._ocontexttop.fillrect( I9 d! q4 x% j; ?, I5 b( d2 o
this._groupselector.ex - ((this._groupselector.left > 0) ?
/ P" _ Q, k5 g/ m3 E4 S1 \4 n4 m0 : - this._groupselector.left),
# S5 s' S) H9 l3 p5 dthis._groupselector.ey - ((this._groupselector.top > 0) ? % J r/ U6 x9 f$ T* b
0 : - this._groupselector.top), 7 [$ R' x. D6 f
math.abs(this._groupselector.left), ! ~) n9 m4 z* b! Z
math.abs(this._groupselector.top)! o! Z' F2 }7 {# i+ r% p. U
);
9 ?0 v5 u3 k) z/ ^, nthis._ocontexttop.strokerect( f' d* U5 L0 H0 v6 L% t6 d
this._groupselector.ex - ((this._groupselector.left > 0) ? ' [/ o- f7 ? G% G# _( I
0 : math.abs(this._groupselector.left)), 0 p6 Q+ q1 H& i$ N6 e) h, @
this._groupselector.ey - ((this._groupselector.top > 0) ? 2 U7 R9 ^& t' C' M
0 : math.abs(this._groupselector.top)), % m! l4 K) W' i M, Y' X# S
math.abs(this._groupselector.left), 9 t2 \& Z% |! e1 E
math.abs(this._groupselector.top)
3 U# s: P" S/ ?& R" s& I4 E);
3 K5 _. [, ~, a9 {$ }} f. \( Z3 B/ R, M
};6 e, m8 }2 _1 {1 w! h$ l
canvas.element.prototype.drawimageelement = function(context, oimg,allowcorners) {% }% W5 ~6 E( X! w8 b
oimg.cornervisibility=allowcorners;3 ]9 u, C0 I2 e3 m% j
var offsety = oimg.height / 2;: h* w# _, @" R8 @9 E& K
var offsetx = oimg.width / 2;9 _, K+ _1 @: B2 o
context.save();
9 ^' F3 Z: Z0 v+ a' k3 A2 Acontext.translate(oimg.left, oimg.top);: J$ x( U% m' N2 C% k# ]- c
context.rotate(oimg.theta);, m! v# a, o3 O3 n h1 P" c+ D4 H% }
context.scale(oimg.scalex, oimg.scaley);
7 S) t6 A% _" }* qthis.drawborder(context, oimg, offsetx, offsety);
1 Q0 H D) F0 E' K0 b- M) @$ I& g; Vvar originalimgsize = oimg.getoriginalsize();
, ]/ N$ B9 I6 q+ W0 Y8 W7 dvar polaroidheight = ((oimg.height - originalimgsize.height) - (oimg.width - originalimgsize.width))/2;
$ h- w- r- @0 D0 xcontext.drawimage(
! V* E' C8 i& Y& W* Voimg._oelement, . T: C8 B9 i" Z! u' Y- ~" p2 k$ l
- originalimgsize.width/2,
; E& h' P8 F" q* }0 E, B5 g((- originalimgsize.height)/2 - polaroidheight),
i$ U( S) B$ J+ q( V2 y% Eoriginalimgsize.width,
5 h* j4 O1 K' ?5 Goriginalimgsize.height7 _6 W2 w6 i1 N
);
* }$ j) }! k8 q6 Cif (oimg.cornervisibility) {1 a% |/ W$ H* |/ d
this.drawcorners(context, oimg, offsetx, offsety); u& ~' B+ X6 j+ D/ K! i( I0 d
}0 D! Z E- ?& R
context.restore();
8 `! G' J( \' e7 v) e0 p2 E};
% A+ I+ L& ]- [5 B/ Acanvas.element.prototype._getimagelines = function(ocoords) {
0 W9 ?$ t* Z7 ]& jreturn {
$ a& S7 v$ A' l( n. B* l' Ctopline: { " l2 e1 X7 ]% O& ?0 [
o: ocoords.tl, h# O" O3 M) J( u. b, s Q
d: ocoords.tr
: G5 I. q" ^6 w* A* ~! D},0 B- N& [6 j0 }( H( y. F
rightline: { ' n- S$ ~: t, o. [5 f4 f: O: C
o: ocoords.tr,
7 b1 K2 q6 p1 A: dd: ocoords.br
4 }5 X( w2 M2 J! ]6 l. E& N) ~},
# s% h: P1 Y8 |bottomline: { : v! [- o! y; L
o: ocoords.br,
( D7 l( C7 c8 w) j/ |d: ocoords.bl
7 d- h' C: J& T( l},
/ Y5 b3 N# @% [7 p. k. D+ p6 Zleftline: {
& o) [- R1 m0 B: \& j5 }4 zo: ocoords.bl,
! C c- E3 \: u" j. A2 h( zd: ocoords.tl
8 f% i5 d2 E! l6 X7 ^}
# j, Y, I1 s8 A: b0 G};7 @% P' ^- m* G; x+ d
};& f( x+ G- F( g
canvas.element.prototype.findtargetimage = function(mp, hovering) {. V6 P2 z4 I* p
for (var i = this._aimages.length-1; i >= 0; i -= 1) {
" Y L5 F: M+ i- t, wvar ilines = this._getimagelines(this._aimages.ocoords);3 f2 Q: ~/ ^7 U6 f
var xpoints = this._findcrosspoints(mp, ilines);! i* C! F! g" A
if (xpoints % 2 == 1 && xpoints != 0) {
0 r% O# r3 L+ j9 _var target = this._aimages;2 U" d2 v: `* q8 i" G
if (!hovering) {( ?7 U/ ~6 c5 f
this._aimages.splice(i, 1);7 D- k- S' k3 E# a0 r
this._aimages.push(target);
0 m4 }: ]/ \9 k+ E, T4 @6 b}
/ G- G* n/ |+ L( U# ]9 h1 K6 D* |4 f' Mreturn target;' e. {2 w1 I+ p& C, k
}, \6 _4 ?9 p" ^0 M
}. j) G3 P3 X+ G T# H" r
return false;
' W$ U1 T+ x9 }; S1 I0 _ C}; : \. p1 O0 M9 l& E2 ?! G0 e
canvas.element.prototype._findcrosspoints = function(mp, ocoords) {& v$ ^! S9 L" w" z$ k; N
var b1, b2, a1, a2, xi, yi;
) ]' L( b/ f9 I" Q/ z! o0 {var xcount = 0;
- n- d1 r8 G( z& _2 nvar iline = null;
: f' X" |+ u; F- m$ M' t5 ifor (linekey in ocoords) {5 W0 ?, x( Z3 O2 u( ~+ g
iline = ocoords[linekey];3 ~9 N' Y1 q" l4 x# j3 q% s
if ((iline.o.y < mp.ey) && (iline.d.y < mp.ey)) {% v7 [4 x; J' b3 J
continue;1 Y' e5 V3 l o: K$ O# n8 N- C% z
} M; U" w! c4 K+ e- }' l+ I' o1 j3 f
if ((iline.o.y >= mp.ey) && (iline.d.y >= mp.ey)) {* F' d/ f6 J/ [3 D: U6 G- d
continue;
! q- x# A' L0 n& S}
0 B; ?& C+ r4 Y0 k! v6 M' }if ((iline.o.x == iline.d.x) && (iline.o.x >= mp.ex)) {
1 t7 |( }( |/ c9 D! wxi = iline.o.x; Y4 g& e6 C, p. V3 \, k
yi = mp.ey;! E9 J$ I7 e0 [0 T
}9 Q9 \7 J1 n2 L6 N$ E3 ~
else {: |8 F T% B" T" G5 T) B
b1 = 0; ' ~) ]. P9 m0 K6 {
b2 = (iline.d.y-iline.o.y)/(iline.d.x-iline.o.x);
2 P6 W z0 h7 E0 l9 s3 \# f& Na1 = mp.ey-b1*mp.ex;) _- V- O M! h' I% h
a2 = iline.o.y-b2*iline.o.x;
% s+ z6 C# G; Exi = - (a1-a2)/(b1-b2);
9 C6 a" w+ u5 j- K) ?$ Xyi = a1+b1*xi; " D% P0 J( w" p' A' u* P' e
}
, s0 s C {, C5 Fif (xi >= mp.ex) {
5 y; m+ S- r6 J% b7 Qxcount += 1;* P/ c/ n+ i: u; s: a+ A
}3 Q6 r4 v! E: ^* N
if (xcount == 2) {* u# J$ }5 ^3 B
break;/ V) X" x! S; @9 P+ x a z$ x
}
# r2 N5 h$ {+ t( p- A7 ^}
3 V" s. i1 c/ j0 A4 V' ]1 L- Freturn xcount;
- m) H8 N) T9 Y8 |7 a/ l};
( m) o1 B7 E3 v) o. Hcanvas.element.prototype.findtargetcorner = function(mp, oimg) {
2 u3 K, \8 A6 u/ S! l% avar xpoints = null;
( [) f, F. c* q. |var corners = ['tl','tr','br','bl'];
* B: ^( C; g3 E* P7 V7 f2 Sfor (var i in oimg.ocoords) {
4 [- f8 B9 {; qxpoints = this._findcrosspoints(mp, this._getimagelines(oimg.ocoords.corner));. E& m8 M) I- }) O% i: L: J) A1 H
if (xpoints % 2 == 1 && xpoints != 0) {1 h& Q' i2 Q" Z9 G- s9 @' o
return i;# }4 k, r9 n) [3 W
} 2 B3 h A2 c1 Y+ R7 F; h& }
}
, U8 R% o3 q) v8 j3 G0 Wreturn false;
+ L9 w: b3 ]/ r; j};
1 [# o' H$ Y, E/ F1 V& pcanvas.element.prototype.findmouseposition = function(e) {- Q6 T' W" f! Y
var parentnode = (e.srcelement) ? e.srcelement.parentnode : e.target.parentnode;
q3 {+ V) {: t( s! m' w0 T- Nvar issafari2 = !s.support.ie&&!s.support.firefox;
) q/ n6 v( u5 [' f! j8 n6 D( kvar scrollleft = document.documentelement.scrollleft || document.body.scrollleft;' |* I9 Q9 d; a! V3 |
var scrolltop = document.documentelement.scrolltop || document.body.scrolltop;: P8 y# l, Z5 u, a, ?) c M1 K" F
var safarioffsetleft = (issafari2) ? e.target.ownerdocument.body.offsetleft + scrollleft : 0;$ ?+ {6 M( O1 M/ C+ @0 z
var safarioffsettop = (issafari2) ? e.target.ownerdocument.body.offsettop + scrolltop : 0;/ ]3 K" C2 ^2 T8 A& F, x
return {
# z% o: e0 l$ r& B0 u& {' x8 [ex: e.clientx + scrollleft - parentnode.offsetleft - safarioffsetleft,
% Y& i/ o, Y5 Fey: e.clienty + scrolltop - parentnode.offsettop - safarioffsettop,7 }3 i0 j Q, M1 }
screenx: e.screenx, O( ~, k$ L# R: I4 h
screeny: e.screeny
# ]. z8 ~5 D" {7 W5 l};
# b } Q) w$ c9 F3 n6 v$ U5 ]};' l4 c- X% `4 x) T
canvas.element.prototype.drawborder = function(context, oimg, offsetx, offsety) {
5 l( E% J5 m" B8 l2 cvar outlinewidth = 2;( t- D6 [7 v" Z! S7 l
context.fillstyle = 'rgba(0, 0, 0, .3)';
5 Q+ x! G6 X3 a& i* Y p+ Ncontext.fillrect(-2 - offsetx, -2 - offsety, oimg.width + (2 * outlinewidth), oimg.height + (2 * outlinewidth));/ M2 P' J- e1 K. p$ _
context.fillstyle = '#fff';/ |# ^/ ]1 X/ f2 x }
context.fillrect(-offsetx, -offsety, oimg.width, oimg.height);2 I0 M( N4 K& q, y1 T- s
};: L* \4 A3 i0 c- e) c3 L' u, Y. E
canvas.element.prototype.drawcorners = function(context, oimg, offsetx, offsety) {) w) [! [/ p3 H. U# s
context.fillstyle = rgba(0, 200, 50, 0.5);+ A$ ]* o7 _8 B: G& {
context.fillrect(-offsetx, -offsety, oimg.cornersize, oimg.cornersize);% ?; I' Q3 X, D5 S
context.fillrect(oimg.width - offsetx - oimg.cornersize, -offsety, oimg.cornersize, oimg.cornersize);
; Q6 `. H: ]0 L/ Q% [context.fillrect(-offsetx, oimg.height - offsety - oimg.cornersize, oimg.cornersize, oimg.cornersize);
4 }7 _0 K& T$ K8 a# G/ \+ Ucontext.fillrect(oimg.width - offsetx - oimg.cornersize, oimg.height - offsety - oimg.cornersize, oimg.cornersize, oimg.cornersize);& l; K) L5 \* L# o9 e |" Y$ X
};! j Y8 n1 c* L2 z O
canvas.element.prototype.clearcorners = function(context, oimg, offsetx, offsety) {
' e( x( y5 G7 s% d* G/ fcontext.clearrect(-offsetx, -offsety, oimg.cornersize, oimg.cornersize);) k# p7 ?! R" @( \) w
context.clearrect(oimg.width - offsetx - oimg.cornersize, -offsety, oimg.cornersize, oimg.cornersize);/ b' C$ Z4 r8 [1 \! E( j
context.clearrect(-offsetx, oimg.height - offsety - oimg.cornersize, oimg.cornersize, oimg.cornersize);
3 v8 q; u/ Y! F u$ f- ^; Ncontext.clearrect(oimg.width - offsetx - oimg.cornersize, oimg.height - offsety - oimg.cornersize, oimg.cornersize, oimg.cornersize);
) K A- A8 z/ K1 Y8 E9 m* n. Vcontext.restore();" p0 c8 D3 q- U9 m; P3 Z$ r+ E
};
) p, p' j1 x% {: Ycanvas.element.prototype.canvasto = function(format) {
$ a- s# Q5 k1 ~this.renderall(true,false);
% e5 c" g3 Z' w1 Q- xvar containercanvas =this._ocontexttop;
7 W: w7 ]/ L# _ D* zfor (var i = 0, l = this._aimages.length; i < l; i += 1) {
7 a$ F* g( N2 n+ x9 g/ D* ], B( \var offsety = this._aimages.height / 2;
+ m" U& U4 [& x) u7 `var offsetx = this._aimages.width / 2;& U) L- N! e% n V! a, u+ x
this.clearcorners(containercanvas, this._aimages, offsetx, offsety);) g! L: E0 M6 d. C9 J# A
}
O+ \3 d% n( I7 ~0 N- g* [* m/ R# Tif (format == 'jpeg' || format == 'png') {
8 Z b1 R! v ], Z) p& freturn this._oelement.todataurl('image/'+format);
. B/ @$ T; [3 U0 f$ i, {}1 O, `8 t* |" S4 l# E
}; " }" l' Q7 `/ U7 A* E8 X7 L
canvas.customevent = function(type) {
! T7 b1 E2 K9 q, nthis.type = type;
) N- C; q! l" w) \this.scope = null;
$ D* E" I4 i8 s( H5 K2 i( Fthis.handler = null;7 U& v- g- j s# k2 [
var self = this;
0 r; C; @! L8 y/ D t2 othis.fire = function(e) {0 [- e( y: P5 j: U1 S) ~* @
if(this.handler != null) {/ ~- n5 n: i2 G2 p) ?- M
self.handler.call(self.scope, e);- X9 d$ t& P3 b0 B; K. B
}
' x4 ^1 ~5 o3 K! O( c3 O};
+ W7 [" x9 ^: P' o/ X}; 3 Z! h; Z: j Z q2 K+ N
}());7 Q3 Y' T, H* I
return canvas;
9 |" Q; r3 p2 Y});4 L7 M3 }# E6 b) A( k2 U
canvasimg.js代码如下:
1 X! m$ y% `$ m3 f复制代码代码如下:define('canvasimg', [ '../multi_upload/core' ], function(s) {7 e' R: Q4 b/ `) e( v
var canvas = window.canvas || {};2 }$ s6 }; R5 T0 V. i) o9 ?" ^3 o
(function () {- [4 r$ t6 a. d3 x0 }
canvas.img = function(el, oconfig) {; J$ @( b( A: B
this._initelement(el);. S2 R% m/ x( b# u
this._initconfig(oconfig);
' p8 A; ]1 }/ b. ?& Tthis.setimagecoords();
& o1 d! e$ _( l9 K' e U% g};' H5 l! Q5 |) Q7 Y0 u- r4 \, K
canvas.img.css_canvas = canvas-img;0 Y& g5 C9 a' ?5 L
var default_config = { 6 b* s9 W; I, H( v. L6 K: E
top: { - I* M/ s( x/ b$ H
key: top,
/ p0 R% ?9 S0 Y1 B- N. |5 Pvalue: 10
) j M( d$ T' ?},
& x( {" R! c7 }' ~% ]6 ~0 z) `left: { V `. {7 w" m. R2 @7 Q
key: left,
% t( o8 q. M r# R3 m9 I1 kvalue: 10* i/ y. G, n* o7 i3 F
}, * ?' `# y& r) c6 g9 a9 J2 L
angle: {
2 d; R @6 s- E- ykey: angle, / J1 p8 s9 _8 k
value: 0
& H$ @8 D7 n/ j3 O6 s/ l},3 \. ~8 s, x* o. h9 }
theta: {
n$ K9 C" D" ^: a" ckey: theta,
: q: z9 [1 W( j! z0 c$ h# Evalue: 0
! ?! D, f; l# [: r},
2 L/ p0 t. Z* jscale-x: { / e9 r) @/ C; u
key: scalex, # Y# v3 ?% n( w6 l! S# L
value: 1
4 k; R+ b7 E& Y1 x},- ?" E/ N: P, e1 @
scale-y: {
& S( n" P7 a. d5 N' @+ t7 X* Bkey: scaley, * a4 y7 S! |1 L! V# m
value: 1
" O" @4 _- p: y% C# L}, a! ~4 c1 R+ U& S
cornersize: { ! B1 h {3 M/ t% {( J8 k! v# \3 k
key: cornersize, % B- x' Q$ m# _% m& R
value:101 o9 `% m3 B6 M Y' d
},! z: `& m8 H( q% q* E
borderwidth: {
$ M8 I4 B2 j6 n7 Akey: borderwidth,
9 r: [9 y( ?1 S" q. Vvalue: 102 s! X4 Q% J% W* }5 x$ f" o$ O8 e
},
# j `7 J5 J6 Q. c0 E+ {8 b' Fpolaroidheight: {+ M8 g3 }6 I; i: w- ]1 Y6 B2 M
key: polaroidheight,4 J: O- m/ {2 B2 _
value: 405 I4 @- }. C0 {% T; U5 Z
},# a. { d/ C4 @9 I5 E6 H* v
randomposition: {) q( ]8 v0 F+ s' S7 a
key: randomposition,
+ Y8 b: q! \2 g. s$ zvalue: true
7 m( [- b% W+ E3 g, C( t/ G1 k( k}
; y9 P2 {* b9 W, A0 w};
$ u& i: A& ~: G4 U5 Icanvas.img.prototype._oelement = null;( j! k |! B! d6 X1 X
canvas.img.prototype.top = null;
, h/ `3 H! }! u2 X8 ?; tcanvas.img.prototype.left = null;
5 P; d! q8 b3 f' W, ccanvas.img.prototype.maxwidth = null;
( _! W$ ^! Q, q ncanvas.img.prototype.maxheight = null;, J% ?& M5 ]5 u. n) T
canvas.img.prototype.ocoords = null;' k) Y2 b/ O! N" u9 p
canvas.img.prototype.angle = null;
* ?& N1 [' F+ Ncanvas.img.prototype.theta = null;
2 }1 j( _ G) F2 h+ C( Icanvas.img.prototype.scalex = null;
0 i3 }7 W! e$ L" ~- |. Vcanvas.img.prototype.scaley = null;6 S) i4 ] b# }& E: t
canvas.img.prototype.cornersize = null;, J( N5 F1 k* Z7 w4 n" l
canvas.img.prototype.polaroidheight = null;
# ~! V- }; X5 D. ^7 m) p2 p. mcanvas.img.prototype.randomposition = null;$ a' V% q8 `! B( A/ c, S6 L) ]+ @' X7 I
canvas.img.prototype.selected = false;
4 {0 L7 J' C9 B0 Y' N. d; v. {/ l Zcanvas.img.prototype.bordervisibility = false;/ _- d+ w+ I% x2 \% i7 D
canvas.img.prototype.cornervisibility = false;/ W0 Z5 H& e, E$ Q9 g6 @; I" p
canvas.img.prototype._initelement = function(el) {( {2 U/ t. r1 @* _( M
this._oelement = el;
2 u+ g- S, p2 V2 Z4 p3 I};
% y) L8 b& c# ?canvas.img.prototype._initconfig = function(oconfig) {. I' p6 l: ^& w! S$ x; g
var skey;
: S8 R5 G) ~1 Yfor (skey in default_config) {1 I* y2 M% Q; M" L4 Q
var defaultkey = default_config[skey].key;' h6 @5 V1 [' G3 ]) m
if (!oconfig.hasownproperty(defaultkey)) { // = !(defaultkey in oconfig)
{+ s3 u' T7 c# R4 f. pthis[defaultkey] = default_config[skey].value;
# x7 q% D+ b; D0 e* I}
( i3 R8 c3 {! R; x* h! f( R6 \3 relse {1 J V. z8 o% g7 Q) _( R, v
this[defaultkey] = oconfig[defaultkey];" }( L4 K( T9 b
}6 s: Y9 G* u- c: n) S8 d
}
! }7 N. P# a' u# o9 x% zif (this.bordervisibility) {: m/ B0 B% b% u9 ^0 A& M' W
this.currentborder = this.borderwidth;# @" ~; O1 Q( V$ B) [; L
}- E; D/ M. ?# Q/ v
else {
- s% U1 @2 f3 f: p# rthis.currentborder = 0;( e) i# {8 G; ]: B/ G6 P
}% p9 n+ q' m* P8 q
var normalizedsize = this.getnormalizedsize(this._oelement, parseint(oconfig.maxwidth), parseint(oconfig.maxheight));
) ~" }% h5 W* I7 j7 X( @this._oelement.width = normalizedsize.width;
* I( @! V* j' z5 a2 Uthis._oelement.height = normalizedsize.height;
% [. {, n0 {. g; o2 tthis.width = normalizedsize.width + (2 * this.currentborder);
( |5 h! S( b, w0 vthis.height = normalizedsize.height + (2 * this.currentborder);
/ k* {, W5 N1 ^% k$ T6 K" b1 T& U! ?if (this.randomposition) {5 l% H4 y* w9 M2 k" Z" a2 u/ q* B
this._setrandomproperties(oconfig);
4 O& h1 H" P' z: \ ~: u$ I( U}, S' `3 x& Y' ?- j- q4 V& |
this.theta = this.angle * (math.pi/180);
$ ~- a- s+ q4 L) d1 D. s};
" u9 [( {0 M7 q0 E, l' Gcanvas.img.prototype.getnormalizedsize = function(oimg, maxwidth, maxheight) {( A3 t* P. J& E7 I1 Y
if (maxheight && maxwidth && (oimg.width > oimg.height && (oimg.width / oimg.height) < (maxwidth / maxheight))) {) U8 @6 r. H5 f
normalizedwidth = math.floor((oimg.width * maxheight) / oimg.height);
$ D# A8 J. I" m, w. v0 F$ g6 P# wnormalizedheight = maxheight;, a& u# Y. d: z$ b( Q
}* l4 n1 _4 t( o% U2 f
else if (maxheight && ((oimg.height == oimg.width) || (oimg.height > oimg.width) || (oimg.height > maxheight))) {0 m& |) B ]# k$ q' y7 A
normalizedwidth = math.floor((oimg.width * maxheight) / oimg.height);! S J7 b# j- b& F3 b0 d0 k+ |
normalizedheight = maxheight;
/ b X8 D7 D' h& z6 |}
4 v. i0 Y2 k( d$ V/ |9 r# L9 B# zelse if (maxwidth && (maxwidth < oimg.width)){
' [' Y; E6 u7 ]1 M Jnormalizedheight = math.floor((oimg.height * maxwidth) / oimg.width);
6 C. q A/ d4 onormalizedwidth = maxwidth;
. d! b$ z# ~, r" M}0 N; d- |) |# D U* i s* i
else {; I! z3 T5 D) ?4 g! l: @- i
normalizedwidth = oimg.width;# u0 e& s( b* ^- ~" ^' H
normalizedheight = oimg.height; a' g8 p S+ ~8 u1 ]! W- y
}/ ?1 \- p5 z0 Y1 {
return { width: normalizedwidth, height: normalizedheight }
! w* ^0 t. ?5 i1 m' H},6 z! c5 N" v1 H k' M- T/ `( B
canvas.img.prototype.getoriginalsize = function() {$ x6 _% {8 p9 t( r5 H
return { width: this._oelement.width, height: this._oelement.height }- Q9 p3 q+ @5 c" a
};. V3 Q0 \8 [$ H7 h2 ^2 D
canvas.img.prototype._setrandomproperties = function(oconfig) {
1 J; }; E: o3 K {) d6 wif (oconfig.angle == null) {
y( r) d1 ?3 `- I% B% I9 r9 fthis.angle = (math.random() * 90);
- A# s8 E. E6 F/ l}
7 |" q C" e Z# z) y+ `7 pif (oconfig.top == null) {5 u) I9 W9 _2 Y. E
this.top = this.height / 2 + math.random() * 450;
) |* l- O& g5 t/ e}, w5 e- R$ }* L7 N9 ?
if (oconfig.left == null) {0 J8 c" y7 j, l0 B
this.left = this.width / 2 + math.random() * 600;( D: V/ u7 A; h, s
}
" o9 n7 ]2 C V}; \ t$ [: V+ `# S' @9 z3 S) O
canvas.img.prototype.setcornersvisibility = function(visible) {! L( }& K' n8 g5 r
this.cornervisibility = visible;
1 \/ H2 {$ k$ }8 ^/ U0 a};
! b* u) i5 |; s! J6 xcanvas.img.prototype.setimagecoords = function() {
. ~4 D- o0 P3 v" Sthis.left = parseint(this.left);0 \. e7 O/ L9 V
this.top = parseint(this.top);
) n0 o5 f; ?$ m# P4 K9 fthis.currentwidth = parseint(this.width) * this.scalex;
- n$ I0 e* b' C2 W, N, k: Wthis.currentheight = parseint(this.height) * this.scalex;
8 J# |1 z" [& C5 ~/ A0 G, jthis._hypotenuse = math.sqrt(math.pow(this.currentwidth / 2, 2) + math.pow(this.currentheight / 2, 2));; @1 E' g! L/ L6 C1 G. l
this._angle = math.atan(this.currentheight / this.currentwidth);, a% Q* ~: n* Q, m# P3 S
var offsetx = math.cos(this._angle + this.theta) * this._hypotenuse;4 |' @& h7 _9 D) y
var offsety = math.sin(this._angle + this.theta) * this._hypotenuse;
" d- T# p2 j, g' ~2 p% fvar theta = this.theta;
. T- P+ U0 r1 I, H: B' |7 mvar sinth = math.sin(theta);$ v8 V3 L+ @8 I3 C
var costh = math.cos(theta);
: l0 G) M. Y/ Q% Hvar tl = {9 z( r5 W t# J" T; D9 P
x: this.left - offsetx,( w# b; T. D' a r4 K. {1 x
y: this.top - offsety
) L$ Q( A$ n+ V4 _8 a- f5 e};
- b7 y9 ~/ p% Wvar tr = {
7 A; Y7 T2 {) H! C6 {7 g6 A, gx: tl.x + (this.currentwidth * costh),
& }7 g7 _/ y/ ]& q! E5 Z gy: tl.y + (this.currentwidth * sinth)1 X3 |* D) r5 W: B
};9 I7 c8 I# W9 _) C1 h( e* }
var br = {; B& w& ?' ?4 I7 e' F
x: tr.x - (this.currentheight * sinth),& k* i8 U2 L$ t. r2 R, A
y: tr.y + (this.currentheight * costh)
8 H7 n$ ?4 N- n* u8 |};
9 ^) }' Q4 s6 y5 b! c2 f7 Rvar bl = {
r# l+ E5 ^( ^! e5 q7 M) |/ b/ Dx: tl.x - (this.currentheight * sinth),% `9 g2 ^! N2 J4 z% U
y: tl.y + (this.currentheight * costh)
$ h& O3 {' \2 _3 M& V, H8 ?" {8 [};9 _3 p8 ^$ i$ L4 P7 P
this.ocoords = { tl: tl, tr: tr, br: br, bl: bl };* l# O& q8 q- I( w" i5 f# X* P' r
this.setcornercoords(); $ t( F) L) q: Z. p
};/ u) ~" A" T- y5 d0 m" ?* O
canvas.img.prototype.setcornercoords = function() {5 {1 k0 P" o9 X7 C5 R# L. F
var coords = this.ocoords;6 e, Z4 m' {0 e4 b f
var theta = this.theta;
& ~0 W3 T! z9 h5 l1 ~& Ivar cosoffset = this.cornersize * this.scalex * math.cos(theta);0 e9 j( Z8 R' ]# X+ u# q: [
var sinoffset = this.cornersize * this.scalex * math.sin(theta);& s6 _$ ^, U$ }8 p# \
coords.tl.corner = {
9 e" @+ y) P5 I# Q& btl: {& [" w8 E7 e$ @8 w k5 x: `
x: coords.tl.x,
. {1 F) }, {+ L# b4 yy: coords.tl.y
) m1 _: L9 V/ i0 m},7 j3 n; k* I5 V" O8 f& P" H
tr: {- l. E! g; N0 D
x: coords.tl.x + cosoffset,
9 M u$ J8 u% u: q/ S; Jy: coords.tl.y + sinoffset
+ b( T. T0 ]6 F},5 S+ R. @% \6 ?! T. A9 M6 { Z: W0 Q
bl: {2 L% \6 T' t/ B9 Y
x: coords.tl.x - sinoffset,, K' O/ s: J2 [2 J
y: coords.tl.y + cosoffset
# p6 H! I0 `9 R. B}9 g& A+ S" _( X( x6 L5 |. h
};
) C- D/ H# b$ _: S0 }% n$ Tcoords.tl.corner.br = {
' J# K; x# c5 Y Ox: coords.tl.corner.tr.x - sinoffset,
0 I+ a& A7 k" v4 ^5 C) k2 \y: coords.tl.corner.tr.y + cosoffset5 x! ~- D* _8 f# Z) h/ B& X
};9 ^/ X. Y$ \4 i7 M
coords.tr.corner = {3 R: G; b1 q5 l+ m. p+ n, T
tl: {- H2 r) h L& c9 H# m4 m# G% x5 T
x: coords.tr.x - cosoffset,
- Y4 ?5 \! |; v! ^" S3 vy: coords.tr.y - sinoffset" A* b. @! S7 l3 x
},0 a& b5 \4 X; e, K# i8 e
tr: {) R( L! L* ^, U% Q2 i" O
x: coords.tr.x,
9 n5 j. J. ^* qy: coords.tr.y
8 { j; N4 E# T, L2 p},# n. f% `& K: E) G7 j
br: {' k* W0 r0 }6 M7 j2 G
x: coords.tr.x - sinoffset,
$ A5 Z$ R) H8 O6 z Y- @& ly: coords.tr.y + cosoffset, B0 U3 z) I4 G6 D; _# r# a
}" r, y+ t2 h* P z8 q8 R
};- K9 E/ a0 {5 P# |
coords.tr.corner.bl = {
- w) Y- o9 N( Y: [x: coords.tr.corner.tl.x - sinoffset,
* I; ^. X8 w8 Xy: coords.tr.corner.tl.y + cosoffset
+ U' g$ I9 z$ S/ Z! S4 t8 c};
9 Q. h2 k* V- a( jcoords.bl.corner = {6 p- Z' x- L8 W% l' G
tl: {
+ @8 y+ W! B+ R$ R0 {- |( ^x: coords.bl.x + sinoffset, ^- S9 |: t% \
y: coords.bl.y - cosoffset; K% E1 m8 S1 U |+ @
},
: q& e4 E. Y8 h* R( Fbl: {( @. H- N. f: K: f! L3 O+ }
x: coords.bl.x,
- F# i& Q; b2 ]- n, D7 z% Sy: coords.bl.y8 D1 { {4 h" Z% r
},. T" p- ?$ |: f0 U8 ]
br: {6 w9 F: t! h5 k. X
x: coords.bl.x + cosoffset," j1 m0 n; a( N8 B" ~8 l' n
y: coords.bl.y + sinoffset$ c7 S0 P" I- M2 i% h. ]9 M, [
}# ~8 x9 z6 T, @' [3 E' ^4 O$ M
};) Y) `/ B9 R+ C+ _9 \" l" K& Z
coords.bl.corner.tr = {0 {& S2 g# p, V8 m1 d
x: coords.bl.corner.br.x + sinoffset," N: m6 x- W A' m
y: coords.bl.corner.br.y - cosoffset8 G# S* g2 A/ ]; }2 [
};$ b. y: L2 k, |6 p6 m; ^
coords.br.corner = {% x5 S+ ^6 Q* S$ q) ]
tr: {
0 o( k$ t+ w1 T/ q) U$ ^x: coords.br.x + sinoffset,
& R1 F6 y. P8 Py: coords.br.y - cosoffset4 S+ J. }, x7 f/ {" u$ i& p( X# [1 K
},8 K% Y0 {' B" z. h3 Q9 X% Z
bl: {4 Y. _7 E8 m8 X- }
x: coords.br.x - cosoffset,
9 Z0 r g" ~) b% Cy: coords.br.y - sinoffset
; e) i2 \( m8 T4 j: T3 @6 _" R4 u* Y},
, G# `# X5 s8 ~% |' Bbr: {- O; t" }) I% L; g7 S( y3 j9 w
x: coords.br.x,8 r$ s* E/ |5 v1 \6 ]( M% p
y: coords.br.y
+ G# P, a% E+ V}% \* c4 d, L* ^2 t' Y8 n
};) E/ _: R* W. e5 a8 r g
coords.br.corner.tl = {2 `5 ^# }0 [) v
x: coords.br.corner.bl.x + sinoffset,# }) _- H+ T7 z0 g
y: coords.br.corner.bl.y - cosoffset
! z9 T/ |/ c% t* b- s0 l};- x+ e0 P7 {; N! f' R) L! J
};' {- p) w4 m5 ]' J& \, P
}());+ k( _/ {) X) L8 |9 Q0 w1 z5 v- S
return canvas;
9 V3 Y& ~& ?, Z9 f2 ]# w3 Z& ~4 D});
9 Q4 w( T6 m" [( Q6 |puzzle.html代码如下:
; p; v( i9 K; S1 B复制代码代码如下:<!doctype html>) B' \/ A9 Z. R" u% N
<html>. I: @3 w$ y1 [; { x
<head>
% o/ s A+ R4 p1 j1 t$ a( N4 m) E<meta http-equiv=content-type content=text/html; charset=utf-8>
! d: ^; I5 W: G0 ~1 @<title>insert title here</title>3 Y. L. |" c* w# X5 J- W4 g, a$ v
<link type=text/css href=html5_puzzle.css rel=stylesheet />
$ D4 e# k* A- n8 N2 F<script type=text/javascript src=../multi_upload/seed.js></script>
! D/ [/ V/ ^( Y0 |<script type=text/javascript src='html5_puzzle.js'></script>* N& |1 \" {1 e. |) ^. {# u
</head>8 J1 `" u; c2 s' |2 s
<body>
, T F9 N/ K8 ]1 s7 m5 |<div id='html5_puzzle'> W# b- ?4 n2 C2 n
<div id='puzzle_left'>9 H/ U; A2 _% X) P8 x
<div class='puzzle_column'>
& l3 F# X Y' N+ q<ul>7 B* ?' k4 O: x; R5 ^
<li><img src='small_img/1.jpg' data-index='1' /></li>0 a. M4 E: _' b. W n" W% }$ [8 E
<li><img src='small_img/2.jpg' data-index='2' /></li>
8 a8 O, A, |$ H<li><img src='small_img/3.jpg' data-index='3' /></li>
0 \+ ?, H9 W5 I8 y1 I<li><img src='small_img/4.jpg' data-index='4' /></li>4 A" R8 N7 R# J% Y- ~ I& V s7 M
<li><img src='small_img/5.jpg' data-index='5' /></li>2 K2 h( z8 ]7 j2 |1 S4 ~
</ul>
3 R8 {. I3 |* f v8 ?' M</div>/ k, ] o0 E8 y/ q8 D' e9 G
<div class='puzzle_column'>
# u& T4 F* s6 X<ul>
4 x8 P2 z' J( N. q. f<li><img src='small_img/6.jpg' data-index='6' /></li>- Z: I3 O5 W4 I+ C
<li><img src='small_img/7.jpg' data-index='7' /></li>
5 \& |7 O4 C( U+ T3 b' a, p% N$ c<li><img src='small_img/8.jpg' data-index='8' /></li>" U6 M$ Q5 x- Z {! K2 G
<li><img src='small_img/9.jpg' data-index='9' /></li>- S9 w# ~- D, k; [2 Z* o& f, [# i+ Y
<li><img src='small_img/10.jpg' data-index='10' /></li>
' F$ h8 C7 O* o& S [</ul>
* L( u& ^; {: Z$ n, q</div>
& [% y& H, z8 \' T! W; E. A</div>
" y* r1 c% h7 O<div id='puzzle_right'>) c" W7 D+ I8 |3 L
<div id='puzzle_canvas'>+ N# Z6 V K+ Y G
<canvas id=canvid1></canvas>% F' l! k2 I/ i2 q2 j; ^' ]: Y
<div id='canvas_menu'>. R `9 h1 ~. @4 X
<a href='javascript:void(0)' id='photo_delete'>删除</a> <a5 T' T6 n; x2 L; {" f- t1 |' F
href='javascript:void(0)' id='photo_update'>更改图片</a>
9 {2 l" W, e9 Y0 t; N</div>
, X; c' j( M' v) S: ], j</div>
0 B4 D5 ~8 Y0 t: a0 @0 x; X<img id=bg src=big_img/1.jpg width='600' height='450' />% E) |* {- D5 h& B7 _! \
</div>
" V2 u5 b9 I3 [4 D. w' u<div id='puzzle_bottom'>4 L9 s g3 ?- n" C' i0 @7 b% Z8 k) C
<a href='javascript:void(0)' id='add_img'><span>添加图片</span><input! N' q9 W- n" P: n; U
type=file multiple= id='fileimage'> </a> <a
7 D0 Q5 V( }' `$ L9 r6 i) `href='javascript:void(0)' id='upload_btn'>上传</a> <a>点击图片可以旋转,拖拽,
- K2 f0 t9 t" O( _' N缩放哦!</a>
' B) r5 H. ~# \0 l</div>9 {& I! a1 ^% l; x
</div>
" x- q- O7 l, m# k<input type=file id='test'># P% r; @) M: Z+ p' A+ a; ]3 T
<canvas id='test_canvas'></canvas>1 D) w/ A! f, x; s; `
</body>" B6 ~7 `8 c3 s$ v! b
</html># r7 e1 d$ F9 x$ }
html5_puzzle.css代码如下:7 I: ^( s3 m9 E! \$ [. D! C
复制代码代码如下:@charset utf-8;</p> <p>#html5_puzzle {
: s+ Y: L9 V2 K% M! G0 a) V8 Tfont-size: 0;
1 `' T6 m4 m8 C4 b+ f! E}</p> <p>canvas {+ {) j2 u! o3 v
background-color: transparent;
& E, w8 E$ I: {* L) _) kleft: 0;: A) C; Y8 }& I
position: absolute;
: K6 b; C6 c: J! a0 {top: 0;7 j8 s; G5 q. D6 D# f& M
}</p> <p>.puzzle_column,#puzzle_left,#puzzle_right,#add_img {" p5 b/ h! ~! H. O
display: inline-block;& X; z& J- U( d4 A$ A
}</p> <p>.puzzle_column li {5 \" f$ W% I" h% ~/ T
display: block; z9 v% P9 C$ q
margin: 5px;
) n. S' z, X9 @1 q' ]border: 1px solid #ffffff;* d! G: L( r" q$ _% b
}</p> <p>.puzzle_column li:hover {; B* K% O4 U; {- k
border: 1px solid #3b5998;- f& N/ G) y$ T! X
cursor: pointer;
0 Y6 l5 V% M8 _# _1 i4 V+ [}</p> <p>.puzzle_column {4 I5 p; A& w; l' z- Y) R0 F* q: V$ K
font-size: 0;$ D7 x0 h, w. \/ b: h, Q
}</p> <p>#puzzle_left,#puzzle_right {% e: a* U' l ~: N3 z
border: 1px solid #3b5998;
! E8 _4 S, k4 t& K% `}</p> <p>#puzzle_right,#puzzle_bottom a {
* y0 J. z3 J( }font-size: 14px;* g: N9 a, U0 O. ?5 f' u: l; B+ `; m
margin: 10px 0 0 10px;
8 V4 z3 o! a! d% y! ?: |7 V, ?7 v0 i0 j}</p> <p>#puzzle_bottom {& V8 W3 X9 P' d1 l4 u' C
margin: 5px 0;
$ a5 P5 C. e/ A; N# W5 n7 u' E}</p> <p>#puzzle_canvas img {
4 U6 e7 a1 Q7 C. w3 d}</p> <p>#puzzle_canvas {
3 I: I# B# D N& v. u7 goverflow: hidden;
/ ^5 G5 S5 W4 F3 V+ v' R2 z1 swidth: 600px;7 \. k# q. J1 J
height: 450px;
" Q; r8 ^0 a. dposition: relative;# i f5 M$ Y7 P3 W6 {8 D' K
}</p> <p>#add_img input {
, `5 z2 T) L8 sposition: absolute;
( R, {3 x. Q8 E* O/ v+ j) L" G* Hfont-size: 100px;8 w$ ~/ t0 B7 R
right: 0;
( n! K% ^5 e8 G! a( z/ R5 {* l" z- @top: 0;' U, p4 P1 T5 p. |" ~& O& N3 T# J
opacity: 0; P) M6 t9 `! l+ ?6 U' S+ ?( O( P& A& ~
}</p> <p>#add_img {
$ W& n6 w' M3 c! }1 N( c+ E1 l3 i, w* b8 Sposition: relative;
* r2 V; e5 q: w: A6 o& |display: inline-block;
( U9 h: H3 b& r6 P6 q- Ibackground: #3b5998;
' D) C/ c: e6 U8 z$ N! r& T3 \border-radius: 4px;
; H2 N# k8 q0 V( G) j' cpadding: 4px 12px;
% ~$ H4 u, O1 \overflow: hidden;# N7 p" W; R. [8 n0 b- j" V8 S# }
color: #ffffff;$ a/ l# \- g' [2 e+ w+ V% a
}</p> <p>#bg,#show_list {
; L# F9 M/ k0 L/ Y. ?5 Y e9 }: }display: none;1 X1 d1 o# ]. T) l8 X0 o
}</p> <p>#canvas_menu {: }* l/ J8 [! _; }
border: 1px solid red;1 }2 v- o7 G$ y8 G' Y
position: absolute;
5 f0 t# [" \- [5 p+ e4 Jz-index: 5;& {7 R5 t; B' Y0 n! y
top: 0;
, B; N C+ `1 W* ^! X! \left: 0;
' E) k9 c! u8 \2 }; bdisplay: none;
) F! K' J0 r$ k( D}</p> <p>#canvas_menu a {
, k0 v1 X, J+ c5 Ydisplay: inline-block;
/ d: s1 I* y0 _0 E: V$ H3 N}</p> <p>#test_canvas {
/ w5 z7 F4 I( ]; G/ [8 f% e6 Btop: 700px;! x& i; C- h, k# w4 M. J
}
6 C2 B1 X, [: J% B0 N8 a5 E" shtml5_puzzle.js代码如下:
. H, z# R% o) [) j1 g复制代码代码如下:require([ 'img_upload', '../puzzle/canvasimg', '../puzzle/canvaselement' ], function(6 I, w% }* Y, b& b4 a
s, canvasimg, canvaselement) {
9 p! H4 T y( `var img=[];. O. h. x# J+ f% E/ F
var canvas = new canvaselement.element();
' T$ ]% g# v3 O' _( f Z2 ?canvas.init('canvid1', {5 J4 v8 g: c( p/ C
width : 600,: t7 | |. @8 E& k! C
height : 450
& d6 o+ {/ R% s5 @3 s});
6 `+ u' e/ x) @s('.puzzle_column img').on('click',function(e){
- X1 X! i. _5 [9 o& Bvar index=this.getattribute('data-index');
" |8 M+ f1 L, j. w+ I$('bg').onload = function() {% D; p( k0 {4 b' C8 ]( U9 h
var ctx=$('canvid1-canvas-background').getcontext('2d');$ m/ ~8 P3 A! T! `
ctx.clearrect(0, 0,600,450);- ?- h1 V) C: K! G' S
img[0]=new canvasimg.img($('bg'), {});" a- \9 i5 s# l- M' }2 M& W+ v
canvas.setcanvasbackground(img[0]); e1 ?! b }( l
};3 R0 Z3 e' u# N$ \, k
$('bg').setattribute('src','medium_img/'+index+'.jpg');
! D4 C( Q' c b v" a1 \5 Qe.stoppropagation();: _$ M7 S5 G0 g* G# Q# A- h5 e
});. l H$ V) V+ _, E- q
var canvasdemo = function() {
, L" B9 U" B4 Treturn {
7 D+ g& }& ?+ Ninit : function() {
. i( H0 V9 \7 {: hvar img_list=dom.query('#puzzle_canvas img');
; Y; J7 s9 @ simg[0]=new canvasimg.img($('bg'), {});
: G3 Z) a( ~" n7 p) ps.each(img_list,function(i,el){& k3 j! {' |% ~$ @
el.setattribute('data-index',i);( ?5 q8 z! i" S- o, ~9 \: r/ Z
img.push(new canvasimg.img(el, {}));
$ u! w2 U w, z, S4 qcanvas.addimage(img[i+1]);3 U/ ]6 w$ O. t& ~$ i9 X/ W: n
});
- d! L& T4 p) L1 U8 B# u$ p9 Rcanvas.setcanvasbackground(img[0]);, s7 D/ ^6 U r, f: ~: W8 a9 A
this.cornersvisible = (this.cornersvisible) ? false : true;/ C ~# P1 p2 }3 _, D) f
this.modifyimages(function(image) {
R3 n* c% ]& K) ?: Mimage.setcornersvisibility(this.cornersvisible);
, q) C" ]8 u5 `% f- ]});
9 z. a( y( ] f6 f! e& @9 n& y},$ N( D; X2 N3 Z) E% {% n7 H4 k
modifyimages : function(fn) { }/ b$ s. q1 [ L: J5 l' [
for ( var i =0, l = canvas._aimages.length; i < l; i += 1) {
5 m u/ H9 y2 P; s2 J8 ~9 Mfn.call(this, canvas._aimages);
* t6 B1 z; @& B* J3 |' b+ Q}
; T4 V* u' L! ^( j/ W6 D& wcanvas.renderall(false,false);1 s7 a3 D+ Z+ l: S7 Z- }7 x6 @! e6 Q
s('#puzzle_canvas img').remove();7 E# V$ n- D! D0 W t% C
img = [];
$ a2 G k6 x+ m7 C}. }- J% h- n$ Z% c
};6 ? ^# N f6 n! p2 C' F- h
}();
2 l9 p$ R% t; [! b0 Z, y6 a4 J( N, W! afunction getcurimg(){
( ~2 t, c' ^! zvar oimg=canvas._prevtransform.target;" a- @, Y& t7 t
for(var i=0;i<canvas._aimages.length;i++){
$ p8 V: {3 J) {% N) |4 [$ m, Yif(canvas._aimages._oelement.src==oimg._oelement.src){$ O+ ^* Z" @4 l+ q9 v* S( j
return i;: R. h, h# \9 @3 e+ Y
}# y/ H$ ^5 I! w' t. F
}
$ x( A$ O0 c3 h6 B! X' Q) k}. A* s2 O. {7 H' H
s('#photo_delete').on('click',function(e){4 p7 n3 R2 J/ G% ?, K
var i=getcurimg();
! Y) t5 T/ }. ?' ^4 {+ Gcanvas._aimages.splice(i,1);- R9 N" c% R5 d2 h: s9 E+ ]+ H7 ?
canvas.renderall(true,true);
% R" Q) }7 g% V2 E" z/ F$('canvas_menu').style.display=none;- a8 d. t+ d3 B
});
- w, Z) v1 R) Es('#photo_update').on('click',function(e){
1 f& C9 b* K# z/ O: ?$('test').click();
/ b3 ?$ A t8 g, O" t) |$ p+ T! F});5 s0 r* S4 u7 {) x
s('#test').on('change',function(e){
# p# W6 S& p, `3 dvar files = e.target.files || e.datatransfer.files;2 J9 e+ ~) r. L0 ?" o/ v
var reader = new filereader();) Q. }6 B }! C$ |" ^5 t9 O# s
reader.onload = (function() {% {7 V: J* |: `; b
return function(e) {7 l% P# R5 `; T o9 V
var dataurl = e.target.result, canvas1 = document.queryselector('#test_canvas'), ctx = canvas1.getcontext('2d'), img = new image();
3 ]( O& ~2 ~$ d) J4 A# b9 Q5 q4 vimg.onload = function(e) {
8 \" w% h2 ^( ?0 y$ D/ w5 Rif(img.width>200||img.height>200){
. `/ x8 s7 g( k6 fvar prop=math.min(200/img.width,200/img.height);( E. s2 C0 E$ F! U, d
img.width=img.width*prop;6 e% J. q; r/ v. ~$ }& _; R
img.height=img.height*prop;
, U; j" |& ~" R! K7 ~}
3 m7 [% z% b+ p0 w* Q% Jcanvas1.width=img.width;2 t' }6 _* f6 r6 A( }9 h- h
canvas1.height=img.height;6 {- E+ h Q% c; {5 g$ a7 B7 o+ [
ctx.drawimage(img, 0, 0, img.width, img.height);( n# z9 Z+ \/ ?3 k, p5 n
s('#canvid1').html(s('#canvid1').html()+<img src='+canvas1.todataurl(image/jpeg)+'/>);3 i' R9 D, @3 k E( d" m! d# t
var t = window.settimeout(function() {. y; ~4 y% b, C9 Y$ d
var i=getcurimg(),target=canvas._prevtransform.target;7 I9 ]$ b" }' w L+ T
console.log(target);$ p0 e2 W$ O# m! R& i7 @9 l) G
canvas._aimages=new canvasimg.img(dom.query('#canvid1 img')[0], {8 r, _& w" R; `: X& k0 `
top:target.top,$ ?3 e* R4 f" r( F3 }0 v) l
left:target.left,
5 X# `* d; X" A' h5 ^$ o4 ` Y( Bscalex:target.scalex,7 |0 P% @5 T1 y1 P: [. s
scaley:target.scaley,1 ?. {. p, M0 c! ?3 B
angle:canvas.curangle
4 }: \( s/ Q1 l/ o8 y});' F: j; C$ A& M0 } P
canvas.rendertop();
0 z& P9 Y3 @; D) L/ L/ acleartimeout(t);% U9 a; w* f* h" {8 O) J
s('#canvid1 img').remove();' T" M# ]! b# E, U5 d: |/ g
},1000);
2 u1 T3 k7 {8 h, D1 Q};7 ^6 X2 g2 D2 F1 G {9 j
img.src = dataurl;" Y+ C. i" n. W% ?
};0 i0 J3 v" w( D# d
})();, o3 a+ r' D: o# @( R8 F1 z# a$ V
reader.readasdataurl(files[0]);( t8 f( y; S4 t, }
});
' B$ `6 K( J$ G W$ N) G2 V2 es('#upload_btn').on('click',function(){
7 i+ H9 s% p! Uvar imgdata = canvas.canvasto('jpeg');
1 Z+ q% Q" F: @0 `" j3 c& L9 t, Yvar imgvalue = imgdata.substr(22);# e) K8 B4 B' z
s.ajax({
; L6 Y1 g- I: S v: F+ ~" `9 Durl : 'http://localhost/html5/upload1.php',) M* A; O" E6 a$ R- _# f
type : 'post',
2 f8 |. i1 s- Edata : {) T$ y; v9 B! J
imgdata : imgvalue,$ e( K6 e+ z) [# J! f3 Z$ y1 q
file_name :'mix_img.jpeg'
2 w( k4 L3 p' i8 k},
! G. a7 N' Y V5 c( O% a4 Ydatatype : 'text',
# i4 \9 ~, ?+ l* H8 Isuccess : function(data) {
" x% s% d6 i! z" ?alert(s); c: c* J( ~9 G9 M. U4 u
}
7 K$ L y- Q% R! O4 g9 n7 { [9 K});
y! V2 M1 }0 }2 x});0 {8 q( w. ~' H- h8 {( n+ A a
});5 P- w9 K- F9 }0 o* q' D0 [
至于用html5 input读取图片,这很简单就不贴出来了。) l3 m& q e- I4 D% h4 w5 D% w
1 c* F; E- Q( u I, B s更多网页制作信息请查看: 网页制作 |