本文实例讲述了html5版canvas自由拼图的实现方法。分享给大家供大家参考。具体方法如下:* T- j B! \' I. E$ t- @
代码运行效果如下图所示:/ ^0 V% E5 u* p. t2 z
. ~5 |& W$ @. H/ t+ W6 x
canvaselement.js代码如下:
; G; Z) M V! F1 R6 G# H% G复制代码代码如下:define('canvaselement', [ '../multi_upload/core' ], function(s) {8 d0 y& V) U& ?) ?
var canvas = window.canvas || {};/ D# U1 h4 o5 z M; C
(function () {
5 q- P& |! S4 T& rcanvas.element = function() {};
$ ~! i9 P" l( {' wcanvas.element.prototype.fillbackground = true;. {, Z" ]- f. }; ~/ H
canvas.element.prototype.showcorners = false;
; [: _/ G7 _" F& T1 e4 f* [canvas.element.prototype.photoborder = true;; Q; O/ w$ c7 ]9 L; ~! e
canvas.element.prototype.polaroid = false;
M& P7 A- B/ H/ U# g) K+ A% [% Icanvas.element.prototype._backgroundimg = null;% Y# H" R3 R5 b5 m0 l% s
canvas.element.prototype._groupselector = null;
& \- Z o# I1 Acanvas.element.prototype._aimages = null;
2 H; G) L' C5 t; ?7 n8 K6 T/ B/ dcanvas.element.prototype._ocontext = null;" p! `4 E: U& V2 I8 K( a$ i: K2 a
canvas.element.prototype._oelement = null;
( V/ q/ D; q' p3 Z% u+ [4 Ocanvas.element.prototype._oconfig = null;; m8 q! p$ |4 @3 l5 X
canvas.element.prototype._currenttransform = null;
* l3 v" z3 h5 Q3 }4 X; C. M- ucanvas.element.prototype._prevtransform = null;
) Y" u9 G; }' E1 `/ j; Fcanvas.element.prototype.curangle = null;+ e* f+ _! Y* u8 T, l7 R5 v
canvas.element.prototype.init = function(el, oconfig) {
5 {! C! G H) O. c2 A- ~1 A2 ?+ W4 kif (el == '') {
1 |" \* Q9 S/ \return;
& r) F/ B2 }0 W& y: Q}) R6 {: X" H% _! {3 P
this._initelement(el);! P5 ^7 p3 Y- |
this._initconfig(oconfig);
5 V! \( l) a, v. Uthis._createcanvasbackground();3 i' S1 |$ X. |1 M9 V- X i
this._createcontainer();. z. c* N8 P/ F* l5 p7 z
this._initevents();
9 P+ D2 ^5 i2 Q: u; _! P% [this._initcustomevents();
d T4 q4 M3 }; Q# N4 Z};7 P1 y' X2 A w' h) Y" ?1 ]2 W7 u6 Y
canvas.element.prototype._initelement = function(el) {
5 J( X* V M7 m. Wthis._oelement = document.getelementbyid(el);
, O7 l7 n* f* V0 ethis._ocontexttop = this._oelement.getcontext('2d');
& b h# J' C, J0 X* \* m& K, A};! `2 c$ F' z7 k U/ X. Q
canvas.element.prototype._initcustomevents = function() {' k& E! o* {0 V3 D% [
this.onrotatestart = new canvas.customevent('onrotatestart');
$ Q- [: \5 k1 R. S: fthis.onrotatemove = new canvas.customevent('onrotatemove'); , F) Q! w' \( _ Q
this.onrotatecomplete = new canvas.customevent('onrotatecomplete');/ @% N: r6 H+ P* y6 Y* K! T
this.ondragstart = new canvas.customevent('ondragstart');
# k+ J4 D. @3 _/ F1 Hthis.ondragmove = new canvas.customevent('ondragmove');% D- F# Q- D- [" w& E
this.ondragcomplete = new canvas.customevent('ondragcomplete');8 p1 j1 |% r) W: m; S, }
};
% o& H, u- \! K) lcanvas.element.prototype._initconfig = function(oconfig) {& f" c. p' ~ V3 G
this._oconfig = oconfig; w( a. L% @- g, j+ i8 @
this._oelement.width = this._oconfig.width;# F; w) |) y- Z" a
this._oelement.height = this._oconfig.height;) D/ \% l8 J% g$ n. i
this._oelement.style.width = this._oconfig.width + 'px';& ]- o! b. r# s9 y$ |
this._oelement.style.height = this._oconfig.height + 'px';
8 P" {- X% S* X J7 n* q2 @};
/ L3 d1 Y$ u0 w6 b5 ]0 y" [: scanvas.element.prototype._initevents = function() {* e0 z8 Y& x8 U
var _this=this;9 Q2 b6 A9 u; T0 }
s(this._oelement).on('mousedown',function(e){5 e+ z0 K; c: x3 e
_this.onmousedown(e);, x( E7 |1 H' K5 s
});% R4 a- K3 d% n$ v: V
s(this._oelement).on( 'mouseup', function(e){1 C2 N7 u% M) b( \% O! v
_this.onmouseup(e);3 _2 _/ f2 n. z$ Z5 I2 T" j
});
$ t! W+ j7 o' Q1 ms(this._oelement).on('mousemove', function(e){
* t3 E. i; M q# E_this.onmousemove(e);" _6 I9 K8 w7 g2 ~. }; H1 v
});
. a) I6 C4 p% q$ h4 |1 S% w2 N. {};' e5 X% I' x! Z2 t- ~* e% `
canvas.element.prototype._createcontainer = function() {9 Z% V- ], [6 R1 K- [: z
var canvasel = document.createelement('canvas');2 ^; B! ^2 z1 w5 n( e3 d
canvasel.id = this._oelement.id + '-canvas-container';
/ G" g% G+ g0 Q* X: ], _4 E0 J5 Dvar ocontainer = this._oelement.parentnode.insertbefore(canvasel, this._oelement);# [+ l. L9 N6 m5 H
ocontainer.width = this._oconfig.width;
; x/ d% W! F! x2 [ Cocontainer.height = this._oconfig.height;
6 o g6 F( \% f5 e$ x& _ocontainer.style.width = this._oconfig.width + 'px';5 m; t2 X6 P2 V- N! N1 x7 \5 F
ocontainer.style.height = this._oconfig.height + 'px';0 p# k! m0 a5 N
this._ocontextcontainer = ocontainer.getcontext('2d'); % p/ j6 k8 L% X# ]/ E, n
};
9 x# D5 Y7 C6 X" scanvas.element.prototype._createcanvasbackground = function() {
9 {5 D* Q# d0 l8 Nvar canvasel = document.createelement('canvas');
3 _- `& W; F# X2 O( ^" s' Ccanvasel.id = this._oelement.id + '-canvas-background';
4 r( d) R5 B1 [5 {$ A1 H: Gvar obackground = this._oelement.parentnode.insertbefore(canvasel, this._oelement);* l/ S7 f# z! B( w4 s
obackground.width = this._oconfig.width; G( v- ^9 c4 W+ O6 l7 j g
obackground.height = this._oconfig.height;
" K, f! t( e5 F4 uobackground.style.width = this._oconfig.width + 'px';
, y0 I9 I; e/ v9 v: J& {) }. kobackground.style.height = this._oconfig.height + 'px';# v% t2 o& z5 D. w! |
this._ocontextbackground = obackground.getcontext('2d'); + C: O: \. l+ H$ Z! f" a
};" c9 P+ B( _$ Q4 W1 L) j; t, K2 Q
canvas.element.prototype.setcanvasbackground = function(oimg) {& G- ^8 Q p# h) c$ O, p6 ~
this._backgroundimg = oimg;; o3 x3 v5 |* ^4 g3 a3 z- I8 S
var originalimgsize = oimg.getoriginalsize();5 z( L, n+ H$ p3 a: W5 X8 \
this._ocontextbackground.drawimage(oimg._oelement, 0, 0, originalimgsize.width, originalimgsize.height);
7 b9 |0 P3 q1 x% O, c};" L+ V a. O+ Q* t& m4 f9 ~
canvas.element.prototype.onmouseup = function(e) {
+ F/ {4 h x5 Cif (this._aimages == null) {7 i, \- z3 x3 X) w' D
return;% _: |! d: d7 D$ i
}
& q4 n9 k+ a3 l0 L5 ]. Y# Zif (this._currenttransform) {
* [* v: I) l9 W5 D* R/ ]this._currenttransform.target.setimagecoords();
% u+ Z! y$ r d- y: E}
3 o+ ~' J% ^. ~% Dif (this._currenttransform != null && this._currenttransform.action == rotate) {! O" R% o* b: [- O, d
this.onrotatecomplete.fire(e);
6 H3 G3 j* O# [. `8 F+ ]: Y5 z: m} else if (this._currenttransform != null && this._currenttransform.action == drag) {8 Q7 j) E* K8 ^7 g+ H; m. ?$ [
this.ondragcomplete.fire(e);
4 K7 r+ w$ E1 \$ w6 b p}
/ E1 n+ G5 a1 K9 I6 ~this._currenttransform = null; g0 t6 ~8 a/ c) F
this._groupselector = null;
- ^8 o4 ?5 |) {this.rendertop();2 k" \- l. r; I* }1 Y$ q4 W/ g; ^
};
x* E% T+ d+ v3 E `1 T9 w7 ocanvas.element.prototype.onmousedown = function(e) {
* G2 u; c3 Y- V% avar mp = this.findmouseposition(e);
8 `. _) ?/ p8 D5 S/ ^( uif (this._currenttransform != null || this._aimages == null) {1 t% S% b0 I. J$ B: m6 @2 O% D; ?
return;
( W, r& V3 ?. u2 p( w3 M( c3 ~1 @}
% A9 P3 M& ^1 L& r" m. e; @ ?5 s& g _var oimg = this.findtargetimage(mp, false);
6 y" D7 \- U, [if (!oimg) {% _* t& R2 y1 X) E4 n
this._groupselector = { ex: mp.ex, ey: mp.ey,
" L+ R8 g/ U5 A1 g2 stop: 0, left: 0 };% }9 t3 n+ r) |, W+ J4 d
}
5 H3 \, p5 e1 D$ selse { G. b5 @+ T X
var action = (!this.findtargetcorner(mp, oimg)) ? 'drag' : 'rotate';
6 t+ A( n5 s, Z2 V6 W4 @* Z- Bif (action == rotate) {
4 q% n9 C6 [3 d" A6 lthis.onrotatemove.fire(e);
; u b' U2 K9 Q, K+ \7 [7 _} else if (action == drag) {/ S" `) \6 `! h( @6 N8 R: d* ^
this.ondragmove.fire(e);% k- p5 ~: \1 H }8 f3 i: L
}; _+ h3 G0 W# l7 U* u6 r
this._prevtransform=this._currenttransform = { ! p7 n: k+ l7 A* g9 ]( m8 z
target: oimg,+ r# k9 n/ b5 i
action: action,
" l' \* f, I- m" \% G; l: tscalex: oimg.scalex,% w1 n: m! t0 }2 {" `
offsetx: mp.ex - oimg.left,+ W( g# [; X' O% \4 M# J' j
offsety: mp.ey - oimg.top,
- A W/ w3 G4 P2 N4 `# n& s# n$ Jex: mp.ex, ey: mp.ey,
; a X2 r' r% A4 Z* ^left: oimg.left, top: oimg.top," k6 j/ m( ` \2 e
theta: oimg.theta : _( L4 v" [/ M
};
! _# |( {; g4 J6 V6 C7 E$('canvas_menu').style.transform='rotate('+oimg.theta*180/3.14+'deg)';- n( u% u; E+ g5 ^# z- b9 p
$('canvas_menu').style.left=oimg.left+px;9 t+ O; R* y9 \
$('canvas_menu').style.top=oimg.top+px;5 Q+ i/ Z ~$ @' ^
$('canvas_menu').style.display=block;# H1 e; F1 ~. C5 t$ R8 F
this.renderall(false,false);8 | v6 ?0 `' m }& Y
}+ ~( v5 A2 {+ Z. N/ u) w$ _& G
};' N y- }$ I, p8 B; H7 W& Y
canvas.element.prototype.onmousemove = function(e) {) w2 f3 E% j% a C1 v( ` r
var mp = this.findmouseposition(e);
! j# ^* w3 C0 }- ^! d& nif (this._aimages == null) {
9 B/ R# Q5 Z- x% E+ Ireturn;
l7 n" Y7 @: C2 [8 }* `3 O9 C}0 w% A. ?0 \3 {( J" A" n3 S
if (this._groupselector != null) {
. l& u6 s3 Z$ g7 j" R5 J0 xthis._groupselector.left = mp.ex - this._groupselector.ex;
: L5 t2 N r8 K& X: tthis._groupselector.top = mp.ey - this._groupselector.ey;4 K: \* Q$ P |
this.rendertop();
$ n! O& w& ^, N8 W% c0 O" p}7 x }4 M% ^* z, g
else if (this._currenttransform == null) {
0 B; m# U( g. w$ J6 i8 n7 Fvar targetimg = this.findtargetimage(mp, true);+ U( F2 }. v+ \
this.setcursor(mp, targetimg);/ `% Q! G! D# H% b' Z4 y
}) X1 h0 C7 m. K% U
else {
7 z' Z' P. J. Y& N6 c2 l3 Pif (this._currenttransform.action == 'rotate') {
$ B- d1 K$ {6 Q, d' f* _* Sthis.rotateimage(mp);
- g8 `; e1 _2 o. C0 rthis.scaleimage(mp);' K0 s5 ^( r: d# L6 F
this.onrotatemove.fire(e);' M* U# @/ @3 P/ m. j/ X" X
} ' m- B8 {& o; w, ]; k
else {
, a5 S9 `; H0 P, J' xthis.translateimage(mp);5 u# g% u8 s" e& }' q7 f
this.ondragmove.fire(e);
! c1 ^- B: P, N& I/ T/ w}# Z! R6 r# t$ C8 g
this.rendertop();
( G3 h, m8 H- S$ K! W" x {}
j4 @1 \: T4 `6 U% C- z};
( x! \6 K1 B8 I( W% y8 b# Ucanvas.element.prototype.translateimage = function(mp) {% r. ^ h( m3 d4 S# Z6 I
this._currenttransform.target.left = mp.ex - this._currenttransform.offsetx;* w5 N% x. Y: a& G" K* ^- C, v
this._currenttransform.target.top = mp.ey - this._currenttransform.offsety;- ?% M* J" y+ \+ R
$('canvas_menu').style.left=this._currenttransform.target.left+px;6 J+ i' @+ z* C5 f5 x# m
$('canvas_menu').style.top=this._currenttransform.target.top +px;
' M5 V1 Y# [) r/ k4 w+ F0 E};3 W" y+ C( B( i8 y9 V- g g
canvas.element.prototype.scaleimage = function(mp) {1 q+ q" n1 q9 d' a
var lastlen = 8 i2 L8 l4 Y- y8 B- @; v
math.sqrt(math.pow(this._currenttransform.ey - this._currenttransform.top, 2) +
! ~& m- x# g Y$ Emath.pow(this._currenttransform.ex - this._currenttransform.left, 2));
5 p2 I7 @- w* y' F# Z& \+ fvar curlen =
) P9 V* D& ?6 @+ C8 z+ Rmath.sqrt(math.pow(mp.ey - this._currenttransform.top, 2) +4 i5 }& b3 g& c1 i
math.pow(mp.ex - this._currenttransform.left, 2));
) b6 `( g/ u+ c5 V) H: |var curscalex= this._currenttransform.scalex * (curlen / lastlen);, c& P4 \( y n. l; |
var curscaley=this._currenttransform.target.scalex;! r# e9 I) A9 o
if(curscalex>0.7&&curscaley>0.7){
* I, I( \$ t2 l0 n/ fthis._currenttransform.target.scalex =curscalex;( P- L7 Z7 V9 |5 [ |* p
this._currenttransform.target.scaley = curscaley;& E1 c2 i! Q5 D1 i7 k' z- r9 ^
}$ M" \5 o: E$ T5 s2 I8 R5 u, _; d
};: v2 L! x7 B! F4 Z
canvas.element.prototype.rotateimage = function(mp) {
. v5 O4 g, L$ W! a, h, p0 @5 S9 evar lastangle = math.atan2(
$ O; s ]3 Q% Q- Rthis._currenttransform.ey - this._currenttransform.top,# f1 ^; K6 N9 b6 V1 o2 Q. G
this._currenttransform.ex - this._currenttransform.left' s. V, |3 V8 Q$ Z
);
( z' W* a: }$ M% P9 T# Ivar curangle = math.atan2(
" R4 H0 e. w8 ~) M! y; ~# rmp.ey - this._currenttransform.top,' Q9 h! A2 x0 U0 X' T J
mp.ex - this._currenttransform.left5 s- v1 H3 k6 p0 a) j, \
);/ K4 o6 A. U. \/ m% }
this._currenttransform.target.theta = (curangle - lastangle) + this._currenttransform.theta; A% u) z p. E# j& } n( o1 U& c
this.curangle=this._currenttransform.target.theta*180/3.14;: x& R" v: M& z( o8 X8 J6 i& S
$('canvas_menu').style.transform='rotate('+this.curangle+'deg)';
4 n& ]9 b4 }( N4 ^7 |};
! D5 s& H3 C! Icanvas.element.prototype.setcursor = function(mp, targetimg) {
/ }- C/ _, `) y% \if (!targetimg) {) K8 W) F- W" d' l
this._oelement.style.cursor = 'default';
/ X$ N9 d8 B5 Z}
4 v0 r% C& a2 L3 n5 \else { 8 [1 H5 ?# `- M$ ~- z
var corner = this.findtargetcorner(mp, targetimg);
7 |- Q* N+ g' Z0 W2 R8 ~- Z+ Sif (!corner) # T8 t$ S1 F; R" A
{1 L7 R- w4 W/ T7 q
this._oelement.style.cursor = 'default';9 ~: p# y# M* d9 Y6 N' S
}% i$ [' R0 o& |9 v
else* y1 {+ s. W- ]- s+ s2 S
{
# D; ?) C8 v+ dif(corner == 'tr') {
. N a' N) }% N- k1 V% l: ~this._oelement.style.cursor = 'ne-resize';
& ]+ Y: }3 w9 s( s% a}
+ A: e9 H' ?( x E! W/ O$ Qelse if(corner == 'br') {
! T7 ?) h7 c& Z D7 Jthis._oelement.style.cursor = 'se-resize';
+ q, I) k$ H. a& \+ n1 R7 `}3 y# g; M/ H9 G5 U; v- y! {
else if(corner == 'bl') {: L1 |5 o# S" B9 u
this._oelement.style.cursor = 'sw-resize';1 S2 O8 N, h9 ?+ p, p3 ^" T
}
0 S. T/ f& d: g7 o: Nelse if(corner == 'tl') {
6 [# _* {5 H0 b8 H) g: j+ Hthis._oelement.style.cursor = 'nw-resize';8 o, u7 p2 I, i+ |9 n3 s
} & m% f u' G6 V* m; w
else {: W3 s( ~. J3 C, r5 U5 X
this._oelement.style.cursor = 'default';
* K0 I9 @, U) p% j, n' n}4 I: F& a" {1 ~6 s' q' w
}7 `( h/ N4 h: b% z! {
}
8 K7 V" U* b- W- [; \% s};) p/ W- C0 M5 o" w) Z! F7 [
canvas.element.prototype.addimage = function(oimg) {
T; a' } p5 g6 Cif(s.isemptyobject(this._aimages)) {% @) j: N Q! a6 M
this._aimages = [];
7 B2 H8 Z5 I ]* ^* r' {2 d}
1 j* i, t7 j# T6 T9 s6 cthis._aimages.push(oimg);2 G8 P K5 R+ b/ f6 d- }% w
this.renderall(false,true);</p> <p> };) C/ ~; R6 g3 m( ]: L, x
canvas.element.prototype.renderall = function(allontop,allowcorners) {
) ]$ o) g _( n4 |- \" C# fvar containercanvas = (allontop) ? this._ocontexttop : this._ocontextcontainer;4 h1 J% y* E; b4 M0 l* k8 U8 R
this._ocontexttop.clearrect(0,0,parseint(this._oconfig.width), parseint(this._oconfig.height));
& i2 @; q, p7 Ncontainercanvas.clearrect(0,0,parseint(this._oconfig.width), parseint(this._oconfig.height));+ U% L# n, ~5 r
if (allontop) {4 R3 A: K, d1 G8 M& j8 Y
var originalimgsize = this._backgroundimg.getoriginalsize();6 D0 X4 m. f7 u0 K0 \6 z. a
this._ocontexttop.drawimage(this._backgroundimg._oelement, 0, 0, originalimgsize.width, originalimgsize.height);
( _( Z+ v9 Y) I( Q$ f}7 T! t, s7 w5 Z. n) i1 H- `' n
for (var i = 0, l = this._aimages.length-1; i < l; i += 1) {( \9 ?7 F; X; T
this.drawimageelement(containercanvas, this._aimages,allowcorners); $ o% r* g& Z: g% G
}
% f2 K- A* Z. _( W0 Ethis.drawimageelement(this._ocontexttop, this._aimages[this._aimages.length-1],allowcorners);: `1 q! u/ T8 D( D) d9 I' n' A6 r2 k }
};1 i n. T H3 g4 s
canvas.element.prototype.rendertop = function() {- [! d2 ^$ T( e4 }) Z$ Z' D3 n) p1 C
this._ocontexttop.clearrect(0,0,parseint(this._oconfig.width), parseint(this._oconfig.height));3 w$ h3 @, H& i& Y
this.drawimageelement(this._ocontexttop, this._aimages[this._aimages.length-1],true);2 c. d. \' H0 j m% w, A2 R5 O
if (this._groupselector != null) {
# C& [( Y5 v. P) f' m# R9 Ethis._ocontexttop.fillstyle = rgba(0, 0, 200, 0.5);2 b& a! S: D" a( {
this._ocontexttop.fillrect(
) k3 P$ z" Y6 H. \this._groupselector.ex - ((this._groupselector.left > 0) ?
: A, u! h5 A) Z0 : - this._groupselector.left), 4 d, g+ [5 `* x6 d" v; \3 a- S$ R
this._groupselector.ey - ((this._groupselector.top > 0) ?
; j& f5 O& x3 `6 X; c6 q2 r0 : - this._groupselector.top),
+ U c- \% |; B7 t( S5 N! T0 Kmath.abs(this._groupselector.left),
, G' G% p% d# C. I: Fmath.abs(this._groupselector.top)
. F. ^9 g, ]* M2 r' b2 ]+ J);
, w; {! \3 P" [this._ocontexttop.strokerect(1 X( f2 e( W( s5 s/ E- P
this._groupselector.ex - ((this._groupselector.left > 0) ? 2 Z9 P4 s+ ?* k! x5 a% r
0 : math.abs(this._groupselector.left)),
$ O# v `* n& J/ b7 W; q( @! \: Ithis._groupselector.ey - ((this._groupselector.top > 0) ? 5 u: ~8 k- I# }$ [. e! i$ ^5 O
0 : math.abs(this._groupselector.top)), " g3 i) D/ w8 F
math.abs(this._groupselector.left),
' r3 n3 ?9 ?& o9 u& z2 ]- R9 j2 _' jmath.abs(this._groupselector.top)
: ~% G) X# r) x);
6 h5 G; x1 q: f. S A1 Q5 ~}
3 E0 G3 X$ F$ ?+ W};0 _) N/ `0 C! S$ O6 e! S* ^
canvas.element.prototype.drawimageelement = function(context, oimg,allowcorners) {
- P$ t7 U5 p# z( |' |8 n; `( `oimg.cornervisibility=allowcorners;; k1 G; W/ Z9 g$ l
var offsety = oimg.height / 2;$ v' o- o2 O/ v1 _
var offsetx = oimg.width / 2;
5 M$ c% n! x% b, b0 Y5 Vcontext.save();1 ^# M% j1 m6 `* ~# ^
context.translate(oimg.left, oimg.top);5 v) P& Q) n6 [$ h w- a o8 F3 M9 |
context.rotate(oimg.theta);
! h! S+ g0 h3 P+ q" scontext.scale(oimg.scalex, oimg.scaley);
n0 r( I" W: Gthis.drawborder(context, oimg, offsetx, offsety);- \( w/ r5 ^+ o* L7 U: g9 S
var originalimgsize = oimg.getoriginalsize();) A) P3 G7 e' h
var polaroidheight = ((oimg.height - originalimgsize.height) - (oimg.width - originalimgsize.width))/2;
! ], M6 o) Q7 \" D# l! `context.drawimage(
4 D5 {9 g/ _. Z" g6 K8 b# K6 loimg._oelement, 6 k" k6 \0 x: L$ P; u8 R0 p
- originalimgsize.width/2,
, x: P. t5 X: f8 o/ t* U+ S((- originalimgsize.height)/2 - polaroidheight), 0 ?7 m3 D9 o1 C
originalimgsize.width,
$ D# `4 v" v: z& toriginalimgsize.height
# [0 C; a" |) f0 U); m+ q3 a5 X, n) j
if (oimg.cornervisibility) {
# \- S n' Z1 vthis.drawcorners(context, oimg, offsetx, offsety);' c+ z1 W, ~+ T, s/ w- M0 t
}
) t. R9 {8 G8 l& k, `) Icontext.restore();. h, @2 D8 T7 Q) g4 c4 T
};" l3 q0 E2 f. S0 P
canvas.element.prototype._getimagelines = function(ocoords) {
9 y: D3 N0 X) k, _return {
# p/ D! A0 _% D" rtopline: { 5 s, P& r- o7 m* i9 h
o: ocoords.tl,
1 r' d8 H8 j4 ~' T7 Md: ocoords.tr 5 [9 _9 i+ Z' T# [% F
},' | E' L9 f: U z( S; H% c
rightline: { * r8 K) M M! G% K/ x
o: ocoords.tr,
1 Y) V2 z+ c& `9 c; [$ Sd: ocoords.br
; S0 l2 M# n5 v- Y3 C; `% j) B},4 z* q$ d6 b7 y+ Z
bottomline: { 4 c0 q( j' ]/ X& m& J+ e
o: ocoords.br,, x, c0 E1 `" D$ @+ l
d: ocoords.bl
$ q! e+ |/ m/ b& ]6 L},
% M+ v6 Q6 \2 e! p3 z$ z9 rleftline: {
: t" j" {* Q2 U7 wo: ocoords.bl,
4 @1 q! d2 w8 U) Q: l% Bd: ocoords.tl % e' U3 v+ ?: f; \& h6 Z
}7 M; o/ q5 |/ i1 S" a5 y
};
# W, v; R8 B( H4 `};9 M6 Q% h# P/ U# W3 X
canvas.element.prototype.findtargetimage = function(mp, hovering) {7 r5 Z; j! [: z6 y, Q: z
for (var i = this._aimages.length-1; i >= 0; i -= 1) {
" V: F( j0 r5 u% m7 jvar ilines = this._getimagelines(this._aimages.ocoords);0 {+ O1 G# I7 Y- |& M) e) P" d B! F
var xpoints = this._findcrosspoints(mp, ilines);1 V0 i+ m0 \3 [: f8 q
if (xpoints % 2 == 1 && xpoints != 0) {9 `8 i9 l' }3 J# m7 V
var target = this._aimages;! S# ~8 B+ B- J5 v) u
if (!hovering) {
4 T$ m+ L) v; T2 R2 D$ ?this._aimages.splice(i, 1);! R$ k! r9 ]; z. Z8 R% P
this._aimages.push(target);" O1 D$ t( f+ B: `2 i7 }* }9 K2 d
}
9 g4 R+ x9 m ~# wreturn target;
, h1 h3 n/ z7 O" l1 `9 L}
# P8 k* q2 U2 j4 ?' K, R* s}
6 r# k! r. A9 x0 l. v6 ireturn false;, ^: ?! d& |1 N/ x' [: |) I
};
# Z* _1 q# W* D7 J! c7 |% }canvas.element.prototype._findcrosspoints = function(mp, ocoords) {9 v1 I+ f4 H/ \( K$ L, e4 u# y
var b1, b2, a1, a2, xi, yi;
8 f, b+ S3 A- r ~! b3 Ovar xcount = 0;
6 h* G% p: T7 c% Hvar iline = null;% s& M& ]8 m9 `7 X }: \, n
for (linekey in ocoords) {
: ^. O1 }# k+ x( j7 {' H1 Y: @iline = ocoords[linekey];
9 i; m! n$ H4 R' Cif ((iline.o.y < mp.ey) && (iline.d.y < mp.ey)) {! o) _5 z9 Z+ j+ y
continue;
$ u3 G: L5 Z8 r/ [; S' R}
$ ?6 [9 L4 g+ B5 ~if ((iline.o.y >= mp.ey) && (iline.d.y >= mp.ey)) {
) g8 Z$ W0 c* U8 ]3 y% k6 ucontinue;8 I/ @& k0 o$ C' S) w; \
}
& d- z6 s3 b. o7 lif ((iline.o.x == iline.d.x) && (iline.o.x >= mp.ex)) {
( K8 T! d4 K4 o _xi = iline.o.x;
( }- w/ E4 ~' L- D: m1 k6 Iyi = mp.ey;6 o# C8 R6 H2 f0 l
}/ i7 U/ @( X- T+ q/ @4 w$ L+ b3 \
else {% a6 f; X7 Q/ L
b1 = 0; / L0 q# O% A5 i% {: K8 u* d
b2 = (iline.d.y-iline.o.y)/(iline.d.x-iline.o.x); 3 | h% b& l2 P! [. Y" t% L/ c
a1 = mp.ey-b1*mp.ex;$ c( C- `% R( z# c6 Z2 g
a2 = iline.o.y-b2*iline.o.x;7 O. q' o3 S/ k4 G( k% ^
xi = - (a1-a2)/(b1-b2);
4 W% \2 _% w. H) A Myi = a1+b1*xi; ! K0 i k9 A. a( {$ u5 j1 Q
}
/ R: G1 e* j8 ^( t7 Vif (xi >= mp.ex) {
- O" R0 U2 ?3 c9 N' Hxcount += 1;$ ?) [$ n8 @- k1 |, h6 n
}* _0 m1 A& X6 e, e% d; t: C
if (xcount == 2) {
8 U8 A+ }) {% V- H: g: a9 Z. o. dbreak;1 F! N* {1 B$ e5 y; e7 W: A
}
* O U; h" A5 J% A4 Z}6 w& W% S" h$ z7 r
return xcount;
9 t7 |8 X# ?3 h Z& C5 K};
0 W3 i3 o9 e4 W8 A6 u. Rcanvas.element.prototype.findtargetcorner = function(mp, oimg) {
I' T+ H3 l4 x# p L/ `var xpoints = null;
1 q% x% ?+ \8 pvar corners = ['tl','tr','br','bl'];7 y E. p9 ^7 b5 ~
for (var i in oimg.ocoords) {+ H6 S8 R+ E* _- _1 w5 I* _7 G
xpoints = this._findcrosspoints(mp, this._getimagelines(oimg.ocoords.corner));
: A4 U5 `; _$ vif (xpoints % 2 == 1 && xpoints != 0) {; H9 k0 I/ S/ n, o. w' D
return i;3 t3 T& G6 m/ K E7 I
}
& W6 Q& H+ V2 p/ y+ M# n}4 i S9 ^) Z' B
return false;
1 K* Q2 n' l8 b# K0 m};3 _6 B v7 {: y$ \# \% W" ?
canvas.element.prototype.findmouseposition = function(e) {
( I( G" I0 \' _var parentnode = (e.srcelement) ? e.srcelement.parentnode : e.target.parentnode;1 D6 d( t9 L: l- v1 H6 r J
var issafari2 = !s.support.ie&&!s.support.firefox;+ ]6 [+ {9 o6 p# S9 I
var scrollleft = document.documentelement.scrollleft || document.body.scrollleft;
( }& t0 @( o, E* Y( l3 K% Lvar scrolltop = document.documentelement.scrolltop || document.body.scrolltop;
# L* E) }9 {5 l7 W' tvar safarioffsetleft = (issafari2) ? e.target.ownerdocument.body.offsetleft + scrollleft : 0;
1 n" A( e: W5 J+ I4 u9 n, tvar safarioffsettop = (issafari2) ? e.target.ownerdocument.body.offsettop + scrolltop : 0;4 w5 d: F2 m; C- l* H
return {
. X: n `; z0 V" n! J. _ex: e.clientx + scrollleft - parentnode.offsetleft - safarioffsetleft,$ ^2 T6 Z5 L c3 q
ey: e.clienty + scrolltop - parentnode.offsettop - safarioffsettop,
+ B* O; i6 t. V) _2 t1 x) a3 ascreenx: e.screenx,
9 u/ p* N7 w# l1 p1 b$ iscreeny: e.screeny
* o% c2 w# c7 g, k( i& }6 v};
2 i, X0 m# h3 e. n9 Z7 \0 {0 C6 d ~};
- e' s4 t, D# y6 w. O: @8 h. Wcanvas.element.prototype.drawborder = function(context, oimg, offsetx, offsety) {5 s; r2 S' C. P4 d! l
var outlinewidth = 2;
- c7 U; k$ X! [context.fillstyle = 'rgba(0, 0, 0, .3)';
( e- C; m# @8 g: fcontext.fillrect(-2 - offsetx, -2 - offsety, oimg.width + (2 * outlinewidth), oimg.height + (2 * outlinewidth));7 y4 Q, z2 q) w7 {" b1 i3 a
context.fillstyle = '#fff';9 T# Y* H% G' Y( t* g2 H& T- L
context.fillrect(-offsetx, -offsety, oimg.width, oimg.height);
# e- ?3 {) c& c- S: n. t};* n" q+ R# h; y, g0 f+ V2 x/ s8 P
canvas.element.prototype.drawcorners = function(context, oimg, offsetx, offsety) {
6 W& @8 d7 U; a; Mcontext.fillstyle = rgba(0, 200, 50, 0.5);
* b# X- d: u; r' n* Z( ucontext.fillrect(-offsetx, -offsety, oimg.cornersize, oimg.cornersize);7 ?' h' V1 B6 }
context.fillrect(oimg.width - offsetx - oimg.cornersize, -offsety, oimg.cornersize, oimg.cornersize);; K0 N3 v/ R8 f9 }* S x* q" z) Q) P
context.fillrect(-offsetx, oimg.height - offsety - oimg.cornersize, oimg.cornersize, oimg.cornersize);
$ ~! f- ?, O9 ?5 f, Kcontext.fillrect(oimg.width - offsetx - oimg.cornersize, oimg.height - offsety - oimg.cornersize, oimg.cornersize, oimg.cornersize);
! A Z( Z# K. t% J7 _( q};
$ w. L4 _' v% x7 [( xcanvas.element.prototype.clearcorners = function(context, oimg, offsetx, offsety) {
6 i. U9 C, W1 H, K: Dcontext.clearrect(-offsetx, -offsety, oimg.cornersize, oimg.cornersize);
5 L0 A8 q3 f; v5 O- v' Ncontext.clearrect(oimg.width - offsetx - oimg.cornersize, -offsety, oimg.cornersize, oimg.cornersize);: {9 f2 K2 W3 c
context.clearrect(-offsetx, oimg.height - offsety - oimg.cornersize, oimg.cornersize, oimg.cornersize);
2 n; U' F, P( {6 `& qcontext.clearrect(oimg.width - offsetx - oimg.cornersize, oimg.height - offsety - oimg.cornersize, oimg.cornersize, oimg.cornersize);' F' @: o( q" R6 N5 f
context.restore();
: P( j# T( h+ x5 V; D- @& i4 L};! @6 O) B% I5 Q$ q* g
canvas.element.prototype.canvasto = function(format) {
! x7 a6 S$ C. |9 J; Lthis.renderall(true,false);- R$ G6 ?' ?4 s. g) N: u
var containercanvas =this._ocontexttop;8 ^! ?" e5 v7 S# _
for (var i = 0, l = this._aimages.length; i < l; i += 1) {
. U1 o0 ?! B" r, T3 Z: kvar offsety = this._aimages.height / 2;
4 y% J9 Q5 y1 N7 f" P0 i/ rvar offsetx = this._aimages.width / 2;9 d D! F( g, @8 b% d: _
this.clearcorners(containercanvas, this._aimages, offsetx, offsety);1 U0 }% @) k( r1 r8 l* i2 }
} K+ g, N, y, a1 e7 H0 |
if (format == 'jpeg' || format == 'png') {
9 S% H7 n: D% [" Q, `) O Y1 t+ ?return this._oelement.todataurl('image/'+format);
6 l+ t, ?& j2 P}
' s+ a* |2 k" F, I' }0 E};
; C0 g& p g, a, @2 q, j# Y6 Ycanvas.customevent = function(type) {
5 V( u$ G, N4 ]; F9 }: uthis.type = type;
9 r7 g3 p$ G2 Tthis.scope = null;
6 w5 I- M* \! a/ Hthis.handler = null;
$ h0 q2 V! a3 _ ^' nvar self = this;
( v% C# t' ^; Kthis.fire = function(e) {" _2 s8 }+ y8 u7 |, u
if(this.handler != null) {- S( R8 L; y! U
self.handler.call(self.scope, e);
$ c1 ~4 k* [, X, R1 s}( a0 I1 p, C6 t2 M3 f- e
};/ c3 s# _4 g8 I3 s& L
};
+ e# _+ g) ?0 G3 M}());
; h- {, A9 }. S7 sreturn canvas;' w1 A0 K* f, T$ U8 X
});
- e# v5 v1 x8 ]2 Dcanvasimg.js代码如下:" y+ p2 `2 E, o! G& n3 [) G
复制代码代码如下:define('canvasimg', [ '../multi_upload/core' ], function(s) {
) s; ]8 h! P; p! Q4 pvar canvas = window.canvas || {};" H2 S& X( ], F/ _
(function () {0 }# Q( d4 K' u- v5 O- U
canvas.img = function(el, oconfig) {
7 [. U) \& m0 Q4 a% S# M( othis._initelement(el);6 a" J4 S- W: R
this._initconfig(oconfig);# B; O2 K- Y# [4 }8 S
this.setimagecoords();
/ T5 M. D. p' l0 n};) Y) [0 P1 \, z9 X+ n& E, z
canvas.img.css_canvas = canvas-img;- R. T Y; }) P
var default_config = { 8 E; p/ l! A) A- X+ Z
top: {
% K3 \ Q9 \; f t: \# ~- ~key: top,
# n3 \( x5 p) w/ lvalue: 10 ' c1 }- |1 c4 q5 V1 M" }; M% I( c
},
1 j4 {7 M; s/ F+ B0 g% A: gleft: {
7 ?, {) }- c! b1 e0 H: vkey: left, + h, w) {# b" v1 V9 U
value: 10) `- ]" K: u& r+ [1 ]. e/ E
}, ; n9 m% e- P) I# p4 M0 ?
angle: { ) R5 j8 q" U- p' A& v7 E% q0 q% B
key: angle, ) v3 x2 G6 i: q
value: 0 ; e8 j" N: y0 g! r
},0 v5 B$ `" ?% Y% |, e
theta: {
( `% G5 | s$ \5 F2 M' {# E) B7 ckey: theta, + `( f4 P- ]+ ~* C: N. p7 w
value: 0 1 f! I5 k$ k) a$ R& a/ q& K' t
},
' p; \" ]! c" P; E/ bscale-x: {
/ n( s, P- X3 k% F5 d skey: scalex, 3 h/ M( ?6 T, o7 I
value: 1 ^& k `3 B7 V6 W9 m3 L
},7 R) _! `3 J* E% W' Y+ G* y
scale-y: {
& C* [$ c; e9 i1 t/ r+ y2 hkey: scaley,
, p) ~& u: [0 P' C# a2 d o+ Pvalue: 1* J! T* ?. Y! z, k: j% V
},* z" _7 `/ b+ K. [5 {
cornersize: {
' e$ g: M( N+ V" O3 }key: cornersize,
* v3 O$ f8 w, i8 Z. \( x# p0 i5 Jvalue:10
2 @" G* w) x; u# e},
: _0 b( M/ A1 y* {2 Eborderwidth: {
9 k8 c$ `0 k0 Q' w* R# pkey: borderwidth, ) {. D2 K N; ^0 G
value: 10+ i( c) Q& c \! s' t" k, t/ W
},
9 u1 m: o( B: s6 A4 Zpolaroidheight: {. f) ]# P, K! j
key: polaroidheight,* u6 k) v$ ]+ Z, W- ^& p+ b
value: 40" A. v7 x8 v0 Z: @5 X9 O! d& v$ Q
}, t0 {/ U' s3 ^2 y
randomposition: { d9 {/ m( s K; ]: x% P0 y. i
key: randomposition,
! m( [- `3 q- N, r5 v. w1 x# N; jvalue: true
: r5 ?% |4 H$ }}* E/ ] Z% ]; f) |# Y
};4 G2 S6 E0 [8 s+ [
canvas.img.prototype._oelement = null;
0 f5 R7 R% g0 [- p1 Y% g/ _& Mcanvas.img.prototype.top = null;
& } j0 @, O# B( p/ y% Lcanvas.img.prototype.left = null; t {9 i& U* }. N0 h) D% O
canvas.img.prototype.maxwidth = null;% F. v3 U3 h* v6 y6 g, _! @
canvas.img.prototype.maxheight = null;
0 W/ d) E# K2 P! W4 f. D3 b# Jcanvas.img.prototype.ocoords = null;
/ Y% I8 n- M- K7 d; @. S: Bcanvas.img.prototype.angle = null;
/ T' U! P' T/ J( X% xcanvas.img.prototype.theta = null;; G, t/ C- W6 u5 i! _' A
canvas.img.prototype.scalex = null;
5 {! i( j h6 D' o4 f- ]' {canvas.img.prototype.scaley = null;& u+ I9 P- @) b8 S* s. K
canvas.img.prototype.cornersize = null;
* N3 y7 C5 W+ U0 Z+ Z1 Ocanvas.img.prototype.polaroidheight = null;) g+ }( E7 \9 o) g0 W2 N) L
canvas.img.prototype.randomposition = null;
! F. c' W; } q& c2 n; D+ i" }canvas.img.prototype.selected = false;, K4 U) _; B6 @! Y1 U$ T1 q
canvas.img.prototype.bordervisibility = false;/ A8 p) n6 [' I" \
canvas.img.prototype.cornervisibility = false;) |! [7 y3 v; \7 O! M* N
canvas.img.prototype._initelement = function(el) {( S* H( {- X( V% S
this._oelement = el;
7 h( ]3 l- d+ `) V. [+ C2 q& Q; f- r};& W5 \% C1 b1 b1 e) }- q, w
canvas.img.prototype._initconfig = function(oconfig) {; N( r% I9 Z1 D4 ~4 ], z4 a
var skey;
; v' F$ ]* ?% d* Y. \for (skey in default_config) {+ j+ A; |! Y2 u. z1 Q/ A7 K: E
var defaultkey = default_config[skey].key;
5 L" b3 o+ o1 u/ f4 tif (!oconfig.hasownproperty(defaultkey)) { // = !(defaultkey in oconfig)
/ \! b, @) Q$ y0 P1 a; Sthis[defaultkey] = default_config[skey].value;
5 e0 ^' i, M! }8 w0 c}+ i! w# c( Z# a/ {4 u
else {
! c4 h& U: |" r+ [. {1 `5 Ithis[defaultkey] = oconfig[defaultkey];
e* Y; K8 n& L6 |% c* m) w0 b}
, C7 W* c: K. j! ?3 _1 n}$ K& ], a& U" B
if (this.bordervisibility) {9 b. ]' \! L* _3 @2 [$ _; W
this.currentborder = this.borderwidth;
/ k3 J N9 J! h: i} s2 f, ?9 X7 p' z. [+ G5 ~: ]- p
else {
k- i# k& O1 L' `this.currentborder = 0;
4 b) l+ q7 w8 _/ {) j}
' S2 S' {- C7 [9 X+ l' Ivar normalizedsize = this.getnormalizedsize(this._oelement, parseint(oconfig.maxwidth), parseint(oconfig.maxheight));) a2 {/ p6 n5 `
this._oelement.width = normalizedsize.width;
* e/ ]% o7 Y9 Fthis._oelement.height = normalizedsize.height;& x4 V, f9 h8 B6 e9 _7 _$ A" h9 f
this.width = normalizedsize.width + (2 * this.currentborder);$ t2 x4 t; X3 U; e h% n
this.height = normalizedsize.height + (2 * this.currentborder);$ K7 H5 j; R# q5 t, P
if (this.randomposition) {" n2 d E' |; K3 G
this._setrandomproperties(oconfig);0 G% o6 R5 k7 ^0 `2 F C, \ `0 v8 B
}. l0 y/ Y6 z! X8 w5 |. w) I
this.theta = this.angle * (math.pi/180);8 f' V4 ^" ] N/ G/ t1 J
};4 \$ g ?* g8 ]- A' W& C$ x
canvas.img.prototype.getnormalizedsize = function(oimg, maxwidth, maxheight) {
& [' r# t+ h& {; ]if (maxheight && maxwidth && (oimg.width > oimg.height && (oimg.width / oimg.height) < (maxwidth / maxheight))) {9 V, j8 V9 m/ D( `0 C; j/ e
normalizedwidth = math.floor((oimg.width * maxheight) / oimg.height);- P# I! C4 w! o* F# D
normalizedheight = maxheight;
3 G1 P8 W% Z* k& q8 Z}5 b8 t7 B$ r" f2 S7 q
else if (maxheight && ((oimg.height == oimg.width) || (oimg.height > oimg.width) || (oimg.height > maxheight))) {
$ B5 ~& D7 B/ z) ^$ fnormalizedwidth = math.floor((oimg.width * maxheight) / oimg.height);$ v5 \$ ^7 h3 _" O" w
normalizedheight = maxheight;
8 C; I0 k# g2 U+ i* X" J R}
+ B7 l1 U& N3 K7 w/ O, {. q9 |else if (maxwidth && (maxwidth < oimg.width)){
& A* t9 Q" m9 k! _% ~$ unormalizedheight = math.floor((oimg.height * maxwidth) / oimg.width);
- S: y& M& ]" t, w snormalizedwidth = maxwidth;
# s2 q# S: L: A# _}3 T. W' `9 y% k& b1 p! x
else {. J* r, y. I3 S9 F/ v7 z2 Z
normalizedwidth = oimg.width;- G) }5 y5 E. e, N; |8 s
normalizedheight = oimg.height; * a* z! u# N! R2 ]3 E1 }' V' ~
}2 I+ n% A) N" R f/ K) h( v8 i! P( M
return { width: normalizedwidth, height: normalizedheight }* l' z. P2 m# h5 i5 |
},, E; N2 E3 s' u1 l$ H
canvas.img.prototype.getoriginalsize = function() {
% N9 h' U+ U8 N) n# K, B d6 n$ Oreturn { width: this._oelement.width, height: this._oelement.height }
' o! h% [7 a7 Q5 U; D};5 D) u( w8 m, u. R% c
canvas.img.prototype._setrandomproperties = function(oconfig) {
1 @( w+ K$ O% d. G+ B ?4 v2 Wif (oconfig.angle == null) {
2 O" p9 V) X/ j* R$ Ithis.angle = (math.random() * 90);2 V7 [ ~3 D# ~
}3 M, G% `8 l8 J0 x3 A$ p5 }& P
if (oconfig.top == null) {( ]( K0 _: F. O" f' C* n9 t; S4 R
this.top = this.height / 2 + math.random() * 450;0 x! p/ X# J) k! z3 ~
}" V* e6 w/ [, _0 ]) R8 ~2 ~
if (oconfig.left == null) {
9 A7 n O9 }1 s* u& @4 r7 D% }3 Lthis.left = this.width / 2 + math.random() * 600;+ m4 B" J0 c& J
}
^1 E: B7 h& a- D* F E+ s' q};
! j* C) s) f) Q6 X0 U w1 `, Zcanvas.img.prototype.setcornersvisibility = function(visible) {
8 J8 z/ V( [+ }) P6 _( W' f% @this.cornervisibility = visible;
1 B, p$ c2 }: }# d- e/ Z: B8 f& U3 q, \};) D' q- r! b* q
canvas.img.prototype.setimagecoords = function() {* u- r7 c' b5 @6 `# r! s
this.left = parseint(this.left);
2 _/ x; \) T3 |: T+ Z( N# Vthis.top = parseint(this.top);; v/ X+ R7 h3 k% K3 T
this.currentwidth = parseint(this.width) * this.scalex;
# C! A6 _; @1 P) l) f- }- Ethis.currentheight = parseint(this.height) * this.scalex;
$ y: {" N, x, s Y3 f- `) c1 kthis._hypotenuse = math.sqrt(math.pow(this.currentwidth / 2, 2) + math.pow(this.currentheight / 2, 2));
5 p, J) v! F$ K! i* athis._angle = math.atan(this.currentheight / this.currentwidth);
; C# _* t) r4 o3 l$ avar offsetx = math.cos(this._angle + this.theta) * this._hypotenuse;6 I( k5 p5 A+ w1 Q' Q8 l
var offsety = math.sin(this._angle + this.theta) * this._hypotenuse;1 [ A" m. x& M
var theta = this.theta;
3 S" L3 d7 V$ ?: h( r! [2 T! vvar sinth = math.sin(theta);8 y- p8 x- j" N4 ]- _" O
var costh = math.cos(theta);% ~: c: D5 u% P, ?
var tl = {
t5 K6 W& C! h- j- {1 rx: this.left - offsetx,
' @! Z- O8 W2 o5 X# V- Ny: this.top - offsety
7 y# b: n* w j3 k! h};* S" Z2 P M0 h5 f& F7 _2 N# h
var tr = { b5 G4 V' T) N1 |6 R) o
x: tl.x + (this.currentwidth * costh),
4 g) n0 ^ y- L8 [& uy: tl.y + (this.currentwidth * sinth)
# q/ I3 C7 N# K};( w% y4 K- U0 M; }
var br = {
8 ^, ~4 b; g1 x8 [x: tr.x - (this.currentheight * sinth),8 g% }, {! x* `
y: tr.y + (this.currentheight * costh)
/ d3 `; y# j" ?6 C1 n};' O6 n4 y( Z: t) E, \( i* F& h
var bl = {
- L% `' C5 L }- lx: tl.x - (this.currentheight * sinth),! Y/ z+ P$ n. N1 X9 g
y: tl.y + (this.currentheight * costh)
& h" ^" e# k. M: Z$ m};6 y* n0 q2 I# X# x% e9 Y
this.ocoords = { tl: tl, tr: tr, br: br, bl: bl };( U/ F+ m4 @% M7 |; ^* _8 }! r
this.setcornercoords(); + O" {% t5 [7 U
};
2 r3 H8 j* M9 k+ X# _canvas.img.prototype.setcornercoords = function() {
% S' M g% p1 q0 C0 c7 Svar coords = this.ocoords;
( j, E* _* a" V4 Mvar theta = this.theta;: e% `$ l; |% n+ m. c
var cosoffset = this.cornersize * this.scalex * math.cos(theta);
/ a& c2 h+ O2 P ^" Z4 Y' X i) r8 lvar sinoffset = this.cornersize * this.scalex * math.sin(theta);% |/ P9 i j4 s E3 b
coords.tl.corner = {' l6 H+ Y' Y* O. j' R
tl: {
0 P8 N" ]* G' W( `, \ p& w2 V8 M( G9 fx: coords.tl.x,+ m- z+ b( \' X
y: coords.tl.y
$ {9 S& E+ B0 o1 ?( S},/ L0 e k" [0 K& v3 [1 q# M
tr: {
8 Z3 R# m( f: y! |, p. l( w- Ex: coords.tl.x + cosoffset,
3 \6 M2 l% I" ~; ]. I: S5 my: coords.tl.y + sinoffset
( R- C: z/ b: T},
% _& C. F4 q& w! h4 ebl: {
- q: r' D% _# Xx: coords.tl.x - sinoffset,
9 i% l ~* H7 B' e& Ky: coords.tl.y + cosoffset( I5 @. c8 C' f/ g# {1 f
}: X" G4 H# [6 ~% ^7 h/ d
};$ [5 ^# [( O1 ]/ }* e
coords.tl.corner.br = {! [7 V8 V L) h
x: coords.tl.corner.tr.x - sinoffset,
! |# D$ ~: r# Q' s, L9 sy: coords.tl.corner.tr.y + cosoffset
( D& }$ b, Z/ k& H2 h9 }. V( V};' d, I2 X" h7 v9 g' _: J
coords.tr.corner = {- S1 Q( P+ k* n* |
tl: {# p5 {" @6 P9 l
x: coords.tr.x - cosoffset,4 C! m5 x) W2 r4 S t) N9 R* R/ T2 K6 K
y: coords.tr.y - sinoffset
0 h4 ^$ c* a* p+ @! H},4 f% x: J$ L' }; q& f
tr: {0 b) B: ?- ?6 O1 S
x: coords.tr.x,
6 z$ o3 F3 w* i" C4 {% w: my: coords.tr.y K* |! _+ _6 M3 W3 R* v& I' U, R h0 {
},
+ m: O+ E7 E. sbr: {
) S, `3 e0 r0 Z5 ]6 y8 K* ~x: coords.tr.x - sinoffset,- J, H @+ P: S& Y" m' z9 @2 ]
y: coords.tr.y + cosoffset3 z6 q4 g) Y5 s& F/ ]8 _ _
}: j1 M! B6 U+ ~+ |
};
* y9 F4 q2 L0 ?0 o Q& Z7 ocoords.tr.corner.bl = {
$ h8 D/ A3 w* S' g9 fx: coords.tr.corner.tl.x - sinoffset,
) `6 b& M- t, a1 t9 G+ Cy: coords.tr.corner.tl.y + cosoffset
4 C' ~( q; F: L/ J};
7 ^- _9 Y1 u& Q" e( p2 P4 t% Ycoords.bl.corner = {
b) l- J: L0 T1 u- Btl: {
# I# [4 v. a0 Gx: coords.bl.x + sinoffset,
7 F. g8 S9 V o* D. @8 F5 cy: coords.bl.y - cosoffset7 G" e: M; }8 p& x) [+ n0 [4 e, |
},
1 A$ \7 l# P* y+ H2 abl: {1 e) K( |) h+ P/ ~9 U4 p
x: coords.bl.x,
! r& n" E. A$ b7 T. ~" Ey: coords.bl.y0 B# t, }) G9 L+ k2 R" L+ k
},
2 w. t* t4 @$ P+ u1 {3 j. h- \br: {; k1 b: ^1 K& j
x: coords.bl.x + cosoffset,% D! O" `. e8 H- U, ]
y: coords.bl.y + sinoffset% _4 i% u3 g% ^$ K R9 J
}
: e5 ^& d- |7 f5 S5 ~+ [1 j};
a" n+ D+ K9 ~! M9 d: j' Qcoords.bl.corner.tr = {$ o0 s. C7 G: i. Q. P% r. ]) r
x: coords.bl.corner.br.x + sinoffset,
0 U/ ], V O0 xy: coords.bl.corner.br.y - cosoffset* C8 M' i8 E$ Q8 `) B9 y
};
, l7 o( T; O! @% p8 t5 V, {coords.br.corner = {
) ~& A. I) e' B9 e V; H2 J- Itr: {( ?8 C7 j, M2 Z7 C7 Y2 e( \1 B8 F
x: coords.br.x + sinoffset,, E0 |- n4 s/ x& q7 s. g! i: G8 `
y: coords.br.y - cosoffset7 @' \7 i# n( v0 a( d# ]
},
/ Y. w$ B& x) }6 L( j# vbl: {
* B5 }. s4 F) d* f7 [x: coords.br.x - cosoffset,* @3 i8 Y' A" G0 S2 w; Y
y: coords.br.y - sinoffset
9 q" y, Y: a- [},( g8 L/ y0 s9 X( z# }
br: {
+ X/ h7 C' G" f% {6 d* qx: coords.br.x,
, m' i, V( ?6 e) By: coords.br.y5 P" y& [/ i, m, u/ b! `: H# d
}4 U# O4 \) t7 i, }5 m1 @
};
; V% g& E8 T/ rcoords.br.corner.tl = {& y0 I, R6 x/ x# N8 n% [( c
x: coords.br.corner.bl.x + sinoffset,
. j0 J, V% [6 l5 p8 Ky: coords.br.corner.bl.y - cosoffset) o# H/ I1 g/ G# O: o
};: X" a' p) [1 \6 k
};! Z& f" J$ Y1 R3 H. c6 t$ M
}());6 z5 v7 v( k% O5 |6 k5 S1 ^2 c6 d7 [
return canvas;% J) R4 f0 Q/ W: w- A8 L: ?$ J# Q
});
0 Y; ^/ O9 \7 c1 D8 u) I ]puzzle.html代码如下:. Z! Y7 T) j5 s+ K( {- N! v
复制代码代码如下:<!doctype html> D) b; u- d2 p o/ Z- }
<html>
7 T4 t1 j- S% D5 t<head>! ^0 X* o2 k& P1 Z; i
<meta http-equiv=content-type content=text/html; charset=utf-8>
% q3 d7 \: Y1 {3 _<title>insert title here</title>9 `5 ~9 Z9 e8 H. L* `
<link type=text/css href=html5_puzzle.css rel=stylesheet />5 O8 V& d' g: S7 o# U5 ]' b
<script type=text/javascript src=../multi_upload/seed.js></script>9 \2 D# R$ n" X8 `
<script type=text/javascript src='html5_puzzle.js'></script>/ }" _$ J; P+ ^3 _1 W
</head>3 q: F. m5 Q u y
<body>
3 J5 U$ D" I, G0 j! _<div id='html5_puzzle'>
$ C* X& T: B/ v5 i- h<div id='puzzle_left'>9 C2 d2 y, g* @7 ?- \( h
<div class='puzzle_column'>8 j0 u- Z; Y! f3 f; B
<ul>
3 Z8 H) v) n2 x$ v( @<li><img src='small_img/1.jpg' data-index='1' /></li>6 Q: D' H ~4 E' V7 J8 H' H
<li><img src='small_img/2.jpg' data-index='2' /></li># }% Q n' c- Q- W. a2 s# U
<li><img src='small_img/3.jpg' data-index='3' /></li>4 V8 F! N5 e' y5 r7 A3 B7 g2 | M2 i2 v
<li><img src='small_img/4.jpg' data-index='4' /></li>) J0 _- @' W) U# [. _% @5 `
<li><img src='small_img/5.jpg' data-index='5' /></li>
7 t+ o: }3 y1 V% ?9 B( Z4 h</ul>
+ h6 x s% I3 S1 U& x5 ~, A</div>
, \6 X: G: z8 v0 P+ {<div class='puzzle_column'>1 O' i8 c V9 T* T! s3 Y" Y* C
<ul>, a/ k& r6 ^! G
<li><img src='small_img/6.jpg' data-index='6' /></li>
1 v' }; w8 i' |& n* n<li><img src='small_img/7.jpg' data-index='7' /></li>8 k0 W( a. T2 P$ X( E) s9 w9 ^: u
<li><img src='small_img/8.jpg' data-index='8' /></li>
6 T0 N! E' O6 a$ N8 ^<li><img src='small_img/9.jpg' data-index='9' /></li>
6 K9 Z( u: t+ I: V' n& A+ I6 a" I<li><img src='small_img/10.jpg' data-index='10' /></li>7 K- n1 i! W3 m- O2 k: X4 {2 @6 T
</ul>
) F4 _7 c5 C/ L! X; }+ y+ ~& P</div>7 `% n( |; @0 q* f9 F* D9 z$ {
</div>
5 q" @- P/ w4 |8 L, h+ t<div id='puzzle_right'>. d- I2 V: j+ N/ n# M
<div id='puzzle_canvas'>. `6 R+ ]) O6 i+ F, I
<canvas id=canvid1></canvas>
% y: u' Z, L; ?, R" x<div id='canvas_menu'>
0 M8 K& \; \6 q( f0 p<a href='javascript:void(0)' id='photo_delete'>删除</a> <a: {9 x Q# r$ M* c8 }! L% n6 \, x' Z
href='javascript:void(0)' id='photo_update'>更改图片</a>
% T; g; q$ L% }# F</div>
2 Y% h r/ h, F, n$ u! ~</div>& E# \# m0 H' {; I* u$ W
<img id=bg src=big_img/1.jpg width='600' height='450' />
: }( I: K, B- @) R# S# k$ p/ ]</div>
9 m$ M9 o, J1 T! j6 B<div id='puzzle_bottom'>( Z" w4 W2 k; m8 _- \
<a href='javascript:void(0)' id='add_img'><span>添加图片</span><input. }/ V4 x/ Y" i" d% v* j: u- |2 Y# [. {
type=file multiple= id='fileimage'> </a> <a
3 {4 |. X3 H4 I) R1 K2 g3 f, ihref='javascript:void(0)' id='upload_btn'>上传</a> <a>点击图片可以旋转,拖拽,1 o0 d; [0 q' |6 G4 d* D
缩放哦!</a>' B6 r( s6 Q( \; b1 R
</div>% a7 {6 C. f5 L7 n
</div>( \: a- @" |% ]5 ~. r, ^
<input type=file id='test'>
% @) ~6 g6 V# ]/ m<canvas id='test_canvas'></canvas>
( a' }* W: W2 E2 j+ j</body>
$ F' J( V; ^5 A" W9 t3 b( f</html>
7 h8 w4 ?5 e; ~, Z% Q4 _html5_puzzle.css代码如下:8 ~3 r. ?" n8 u
复制代码代码如下:@charset utf-8;</p> <p>#html5_puzzle {( _' n* e. t$ E
font-size: 0;" b# |2 j5 n! w- y/ X0 J4 J
}</p> <p>canvas {
" G, R! t. J6 d. U$ ^background-color: transparent;& v8 j& z6 u- o, `% v$ M1 {
left: 0;& Y! o" T# O" q) Q4 `; D1 P, W8 T
position: absolute;
8 m, T" [" Y, z# ^: T- `# z0 Q" Ftop: 0;
+ {9 q( {: Q" z5 p}</p> <p>.puzzle_column,#puzzle_left,#puzzle_right,#add_img {
. j) |" G5 C8 ?# T* F3 sdisplay: inline-block;, }, @8 s( Q4 P8 z" @! b! w
}</p> <p>.puzzle_column li {2 Y$ N6 p5 T* j8 [% O; a
display: block;
' A6 v6 U, V/ j' B) x6 z. hmargin: 5px;
$ X) M( h+ ]! z1 j, N Hborder: 1px solid #ffffff;
, K$ h& O, Q3 N% O3 T3 N- {% Z: c% E}</p> <p>.puzzle_column li:hover {& m% q& `% Z; h
border: 1px solid #3b5998;
( y% Y/ M0 L/ @0 m Wcursor: pointer;
# n0 |2 A6 Y# E2 k1 b}</p> <p>.puzzle_column {
E% X G& Y/ i& D+ F1 @font-size: 0;
, d8 U+ k/ O" c+ B9 q}</p> <p>#puzzle_left,#puzzle_right {
) f/ U! T: |- P5 }# }, m) }border: 1px solid #3b5998;& Y) Q5 }8 `. K1 q! s) V$ _
}</p> <p>#puzzle_right,#puzzle_bottom a {7 \: ?" {; N: J& [) n
font-size: 14px;& g- f$ n4 ?# R* b. D5 I% L
margin: 10px 0 0 10px;
6 g- p$ R1 U; x# ^ O}</p> <p>#puzzle_bottom {
, w' d' p) L( \" z6 I6 smargin: 5px 0;
; B! f1 Q' \; T ?}</p> <p>#puzzle_canvas img {
# C' ^' s, B+ u$ }+ f}</p> <p>#puzzle_canvas {1 `3 J1 H: }/ P% R, K% h
overflow: hidden;" U" Z: C8 a3 }0 k4 |) n
width: 600px;
5 u/ o3 |$ C5 x- h; N% |0 Jheight: 450px;
2 @: _+ d7 w; }- X7 ~4 y& c+ n9 |& Rposition: relative;; B( ~9 k$ t, {
}</p> <p>#add_img input {
; f4 O: Q1 |' }9 U& Yposition: absolute;
( ^1 U( `' D @7 B8 H4 _- Zfont-size: 100px;
- G1 Y" S* Z' b+ r0 \( E$ Zright: 0; {5 H2 n' Y% r
top: 0;2 k1 R# v( a1 H7 T. F3 j6 ~8 K6 |9 h3 v
opacity: 0;
5 |# C5 j* I. O/ v6 I9 \- \- P}</p> <p>#add_img {* M$ h4 Y# ?5 t8 f# H
position: relative;
6 ]3 h& U3 p; p) m" t9 Q2 bdisplay: inline-block;
: E. l$ F/ K2 r# n/ ibackground: #3b5998;0 l* I" @ j0 Y6 V! ?/ g
border-radius: 4px;
" _- O: W% p4 J' s. cpadding: 4px 12px;( \) r$ l2 j( ^, M6 O$ k8 E
overflow: hidden;6 ~% k, z2 n R. q! k) f6 g$ @2 q
color: #ffffff;& P1 U$ p2 A: m. b; x( h
}</p> <p>#bg,#show_list {8 ^! u2 S1 ?5 J' H' B' ~
display: none;2 d7 C9 m& v" A+ p! [% N
}</p> <p>#canvas_menu {+ e3 J7 q2 ~ m9 K/ `+ ]
border: 1px solid red; D( B2 R* V1 k; {; L( Z6 u
position: absolute;
" y" X2 t5 E! X: O: ez-index: 5;
! D' B& Y4 H4 htop: 0;" `) u: v& R( x. u. J/ N6 l
left: 0;
, R4 Z2 N, R; n( Tdisplay: none;& p; M, G0 K/ ^0 [% _* l' u9 Q' {% R
}</p> <p>#canvas_menu a {! N& n" Z# ?) D2 ?
display: inline-block;3 n' ^; f6 W) P7 S m
}</p> <p>#test_canvas {
, q0 u& m+ U7 S0 wtop: 700px;
* i5 h1 v$ q. r. `3 q}
( m' M8 q( \# `html5_puzzle.js代码如下:
* A I3 q+ G. [6 ]( p复制代码代码如下:require([ 'img_upload', '../puzzle/canvasimg', '../puzzle/canvaselement' ], function(
1 [4 q2 v& T" L% I# X* k; H3 Ns, canvasimg, canvaselement) {- E/ ?3 A9 E& Z d, Q
var img=[];5 p+ S% S3 e2 Z+ x
var canvas = new canvaselement.element();% L! f- D3 C/ _# g3 M% B# Z
canvas.init('canvid1', {0 Y; ]' ] \. B. y# Q' k4 `
width : 600,! i% j4 O6 t4 Y/ z9 e% ]
height : 450& W; d# x0 r$ m' _" y9 F9 `( C
});- e( F- b# g. H, }* Q: k
s('.puzzle_column img').on('click',function(e){3 i& L; \& w) U: c1 p
var index=this.getattribute('data-index');
* {/ M; @0 P% e; p$('bg').onload = function() { z, `0 y7 p% b
var ctx=$('canvid1-canvas-background').getcontext('2d');" I1 ^0 U! ^7 V7 U7 y c) j
ctx.clearrect(0, 0,600,450);
% ]( ^ x7 U9 K8 kimg[0]=new canvasimg.img($('bg'), {});
) q2 p# W( Z: x: Q! V- wcanvas.setcanvasbackground(img[0]);0 w1 B; p: b9 V% g( Z
};
- z" r9 j! l/ n; `$('bg').setattribute('src','medium_img/'+index+'.jpg');) ]: k: _3 B9 M' m
e.stoppropagation();
! d$ A9 n! F" t4 B});
8 h& C- Q0 J4 D( F. S4 I( f7 F# T) s1 Evar canvasdemo = function() {
9 Z) j1 h2 M3 y& \2 Dreturn {
4 C! }3 M& W/ C% Rinit : function() {6 ~+ k: I6 B- O
var img_list=dom.query('#puzzle_canvas img');0 l- W3 U: k. C
img[0]=new canvasimg.img($('bg'), {});
" V, e6 g# s0 o( i: Y3 |s.each(img_list,function(i,el){. p/ B$ i# u. l% W
el.setattribute('data-index',i);0 T7 u | ^" |; {) {7 r
img.push(new canvasimg.img(el, {}));
7 n& I) g6 R) D! Ncanvas.addimage(img[i+1]);2 q+ R2 D3 j) I) |: C) a
});
; x. g. N4 [4 W" Ncanvas.setcanvasbackground(img[0]);$ j# A1 c, X# c: w5 @" m
this.cornersvisible = (this.cornersvisible) ? false : true;
- Z* }! X7 L& N% Z5 j' b2 |7 `. E7 Xthis.modifyimages(function(image) {
" t: X8 L! G2 {; o# Mimage.setcornersvisibility(this.cornersvisible);# {% q$ E* n, g S( X( ?2 q' u- ^5 }
});
/ \" g/ D# y% b' q},
* {5 l4 b# G8 c hmodifyimages : function(fn) {' q# l, x4 Q7 Q( q+ y ]0 [
for ( var i =0, l = canvas._aimages.length; i < l; i += 1) {
# C$ F) s- z: s* }fn.call(this, canvas._aimages);0 f' X( _1 ?5 }+ k0 P |
}
- K% R$ H, D' R2 \( Tcanvas.renderall(false,false);! D( P: B% b0 U" j4 M
s('#puzzle_canvas img').remove();
, e2 o% s$ n; |img = [];
3 ]. p; W3 Y9 T% }: t}, E& l1 O4 r+ u2 }8 j, A
};0 n, j: W5 a' D' T/ {. D
}();7 w9 m& b# t5 p9 v" i7 I. N C# N
function getcurimg(){3 P. `+ l; p& j& Z8 F5 G
var oimg=canvas._prevtransform.target;
8 X9 N1 B4 d# E- V1 f6 D2 Afor(var i=0;i<canvas._aimages.length;i++){
7 v* {) U8 a: \+ I) B& P, |6 jif(canvas._aimages._oelement.src==oimg._oelement.src){
# B0 m( \: E7 q9 mreturn i;
( ~1 o) Q# _% H7 [: m}9 v& N8 `1 J5 H' O0 l4 b3 r
}
1 S$ r% d8 q: H M; r6 b W}
, ^, k* E! x$ _- `0 E% J9 ys('#photo_delete').on('click',function(e){
; @0 w5 `- k r& s; ?var i=getcurimg();5 E( x: P. T x9 x" q4 r" `
canvas._aimages.splice(i,1);' l$ F$ r b" [+ t* f
canvas.renderall(true,true);% g0 ?# i7 T: k n7 b, \
$('canvas_menu').style.display=none;* T$ f6 N. e- K2 A; e' c9 u6 X
});
) S8 V) p( r. @8 L9 P' ns('#photo_update').on('click',function(e){
( z) q, a5 J1 H$('test').click();
, ~; x Q. C0 X- F8 Q});# K% |. G: z0 p) L
s('#test').on('change',function(e){+ C6 w% ^+ ~ s0 x! X
var files = e.target.files || e.datatransfer.files;
6 e" t! c$ {. m1 f. ~var reader = new filereader();1 A8 S P |5 F9 J
reader.onload = (function() {+ ~7 l- u4 f9 ^. S2 r
return function(e) {
. S$ F" n5 Q8 S3 c% @- tvar dataurl = e.target.result, canvas1 = document.queryselector('#test_canvas'), ctx = canvas1.getcontext('2d'), img = new image();( H$ O8 C/ {# ~6 S
img.onload = function(e) {
# u- i _7 u1 B1 iif(img.width>200||img.height>200){
- O7 s& F1 X; Q2 f$ m8 |& V, j& Fvar prop=math.min(200/img.width,200/img.height);( t: @) W) o& J0 k! R
img.width=img.width*prop;
[6 E9 D$ a; f! O; Timg.height=img.height*prop;
# j& Y7 E; I; Z: {+ T; M% @}
# h$ c# K" ]& B9 O/ x" u$ tcanvas1.width=img.width;
& x8 c+ Y- J; v. Ncanvas1.height=img.height;
3 o9 }8 t+ l- n8 A! G8 Jctx.drawimage(img, 0, 0, img.width, img.height);- f7 w" H7 z( O) Q
s('#canvid1').html(s('#canvid1').html()+<img src='+canvas1.todataurl(image/jpeg)+'/>);
8 \) p7 b2 h; T C: m$ Mvar t = window.settimeout(function() {% E7 f& d5 |: l5 e
var i=getcurimg(),target=canvas._prevtransform.target;. K! Z# G: _" t
console.log(target);
: A( S& q2 A1 u9 ]9 x7 v x3 `canvas._aimages=new canvasimg.img(dom.query('#canvid1 img')[0], {" i, j7 L4 m# l. j: G6 o( w& M- f" E
top:target.top,
& ?- `6 f( v0 q: p0 aleft:target.left,
: S% @9 Z7 {6 ]7 T& fscalex:target.scalex,, J9 X6 Q8 ]& D/ N Q- N
scaley:target.scaley,
1 _- a7 E$ t$ e# @( D( Q( ~angle:canvas.curangle* R3 T& Z+ `6 e1 ?& \7 O9 D0 N. |' u
});. H2 }2 Q- {# u
canvas.rendertop();
8 J# ~+ T2 o8 I3 i3 Ucleartimeout(t);
& }% T, }9 e! s7 ?s('#canvid1 img').remove();: u1 E7 _. [! J) u' v* f
},1000);* ?7 F+ R; E$ F/ @9 Q/ Q, \
};" ]" k5 i4 ]# i2 X/ S
img.src = dataurl;
6 k9 D1 A; y, ?7 k, g$ [5 E3 v};
+ F) H) y: a# t7 }9 S' A})();4 j( B9 j5 V/ z; S$ B- v
reader.readasdataurl(files[0]);
. |4 U8 [$ a& T) u! C& ^: j4 O});
4 X* t6 @3 v5 z1 I; H! Z( gs('#upload_btn').on('click',function(){
9 e6 F9 x( a7 {2 o7 R1 m/ @var imgdata = canvas.canvasto('jpeg');
4 M+ ~4 w, S" Q {* hvar imgvalue = imgdata.substr(22);0 I- g6 V) N$ |& U8 d, ~8 s
s.ajax({$ p1 w# R6 l9 e! b: o
url : 'http://localhost/html5/upload1.php',* a, U5 E( Y6 y" |
type : 'post',
* b) P/ l) q* k! X7 a/ \& sdata : {8 R+ {( E# n$ r
imgdata : imgvalue,
" ?- s- ~( ?+ k/ Ifile_name :'mix_img.jpeg'/ |- W* T9 w8 b% M) Y1 @& Q; h/ D: S- N
},
- Z, U" v/ a$ w- X# mdatatype : 'text',
% O" V; L1 e+ L P# @+ x# b0 _) csuccess : function(data) {
# }$ v6 G ]* n8 D0 r4 ~% zalert(s);
2 _. Q6 F2 j- d5 w3 U h: G' N}
) Y% ^, X+ B# l3 L% k! z5 c});
7 F9 G) a1 R2 K. H2 u});/ _( C8 i' \2 S8 r# E
});1 p' |4 l7 v+ T5 y
至于用html5 input读取图片,这很简单就不贴出来了。$ S7 s; E1 V* `
5 N8 `; Z3 p a) |/ q更多网页制作信息请查看: 网页制作 |