本文实例讲述了html5版canvas自由拼图的实现方法。分享给大家供大家参考。具体方法如下:
* U. S# r1 M. W9 S8 p代码运行效果如下图所示:0 a& ~, n4 l: C$ D5 \
* z2 ^3 H) L H) I* R( z! \
canvaselement.js代码如下:
5 V# F7 Q/ w- N5 ~. F9 t- k( N+ D& y复制代码代码如下:define('canvaselement', [ '../multi_upload/core' ], function(s) {) g7 r+ U5 L' l2 u V
var canvas = window.canvas || {};
" T" u; D8 B n8 M- n, i; v(function () {8 ^3 \# [8 P* o+ [3 f$ _
canvas.element = function() {};
: s* x# M% C) R% Z/ {canvas.element.prototype.fillbackground = true;+ O$ z- f- M) R" |8 r! K4 Q/ e l! a7 A/ K
canvas.element.prototype.showcorners = false;1 R7 o2 e8 v+ u2 O( s5 o
canvas.element.prototype.photoborder = true;
6 n. u6 u5 f0 _& Tcanvas.element.prototype.polaroid = false;
8 v7 l b8 E1 M& K- W( f& Scanvas.element.prototype._backgroundimg = null;
5 r- K/ P8 d8 S! Pcanvas.element.prototype._groupselector = null;
, U9 ^( k7 q! p5 ocanvas.element.prototype._aimages = null;# F5 J+ I2 B# A
canvas.element.prototype._ocontext = null;3 u! k6 g% @, `6 D6 l, g
canvas.element.prototype._oelement = null;! e" B$ d% x0 A$ B8 L s( [
canvas.element.prototype._oconfig = null;3 s- R d& f" m
canvas.element.prototype._currenttransform = null;& \# ^! w0 y& l* ~1 n5 N4 H
canvas.element.prototype._prevtransform = null;
* R! G. X* R9 `$ `' H3 |( pcanvas.element.prototype.curangle = null;/ Z. `' x F1 s% W: J1 I, U
canvas.element.prototype.init = function(el, oconfig) {; r$ A, M- D9 }6 n1 O
if (el == '') {
7 d% I6 X& x* x/ A3 n8 S$ [return;6 W2 ?9 a+ K# p4 H$ f
}$ }% j" C9 W B6 J
this._initelement(el);
& s* s4 Q; R5 R/ [! F, hthis._initconfig(oconfig);
1 R, ]0 {/ V' |, K" e& N7 }this._createcanvasbackground();
& J* A3 \( @# L3 @# i$ P* nthis._createcontainer();
; V1 n6 ?2 c3 sthis._initevents();# L, A* h' v1 d4 V. i( H' L* h* t
this._initcustomevents();
- L0 x+ ~" A* W, Z" g};# @4 k. V+ c6 T5 ?
canvas.element.prototype._initelement = function(el) {
. r6 e8 ^6 o0 mthis._oelement = document.getelementbyid(el);5 `' [/ \! z0 h* D1 Z6 ?
this._ocontexttop = this._oelement.getcontext('2d');4 q1 p5 ~( X: U0 l# A
};- K9 I6 _8 j( ^7 ~
canvas.element.prototype._initcustomevents = function() {
y' Q7 X- u* w* s4 w- qthis.onrotatestart = new canvas.customevent('onrotatestart');
( T. q8 J# n' f9 z* A' ~) pthis.onrotatemove = new canvas.customevent('onrotatemove');
2 X& E- _+ k8 ?this.onrotatecomplete = new canvas.customevent('onrotatecomplete');& ?+ s, H2 z, m+ c5 r
this.ondragstart = new canvas.customevent('ondragstart'); , |- M+ k! |- J/ w5 _4 ?9 [3 {
this.ondragmove = new canvas.customevent('ondragmove');
3 z7 S+ r( r9 w" J+ }# T) u9 X+ C9 ethis.ondragcomplete = new canvas.customevent('ondragcomplete');
- y9 T# A) w9 @4 S};
8 [. Y5 A+ G4 G0 w: Y9 ^1 }canvas.element.prototype._initconfig = function(oconfig) {( _; @1 B; `9 L1 ?( U: L/ C
this._oconfig = oconfig;/ g3 P; l9 @/ V7 B
this._oelement.width = this._oconfig.width;
o3 z5 @3 X3 g* Cthis._oelement.height = this._oconfig.height;
6 r6 j' V# i8 n3 Bthis._oelement.style.width = this._oconfig.width + 'px';
# n& r3 j$ \, W5 k3 Bthis._oelement.style.height = this._oconfig.height + 'px';, \2 Q% L6 x$ l7 N* E2 z9 a7 S
};- C2 d. J# v4 L
canvas.element.prototype._initevents = function() {- ]# [5 h ]& l# m% q) f3 `5 I
var _this=this;6 Z1 S$ o' v9 S' F* }
s(this._oelement).on('mousedown',function(e){; o \ K8 o" c I. y% u$ s6 I
_this.onmousedown(e);, M6 A* B3 f3 |9 T6 J
});. F8 t0 b Y: x8 _3 Z0 K+ ]( J* J
s(this._oelement).on( 'mouseup', function(e){; h' W4 Q8 v# U: N. A
_this.onmouseup(e);
: L5 M" l2 ~! n# @7 C) I8 }});
: B. Y x H6 F- as(this._oelement).on('mousemove', function(e){. `. ?7 T9 Y7 {" e
_this.onmousemove(e);7 s" D; v3 u3 _/ s+ G
});
/ X( z, r' s* f: K8 E9 ~9 j: w};
7 o0 |8 R4 e* E8 kcanvas.element.prototype._createcontainer = function() {
2 x! L! h' R4 X. c; Wvar canvasel = document.createelement('canvas');
: c. ~- f" r* ncanvasel.id = this._oelement.id + '-canvas-container';9 o% K. E1 c3 ], `/ x
var ocontainer = this._oelement.parentnode.insertbefore(canvasel, this._oelement);
* d/ z, s @# nocontainer.width = this._oconfig.width;8 k$ l [' Y" F. b" z0 a \
ocontainer.height = this._oconfig.height;2 p1 k4 k: r& j7 W# y8 e! k
ocontainer.style.width = this._oconfig.width + 'px';
+ E% X" d/ C) q) y7 j7 R' k9 rocontainer.style.height = this._oconfig.height + 'px';/ Y, y' I) o2 t. W- X
this._ocontextcontainer = ocontainer.getcontext('2d');
1 D5 h( b# K5 J# M- i, m- _ C};6 l+ d5 ^6 T3 k' g1 e, P4 b
canvas.element.prototype._createcanvasbackground = function() {
9 L: v/ `/ r2 c7 ^$ Avar canvasel = document.createelement('canvas');. e2 H( a* h- y6 B4 G
canvasel.id = this._oelement.id + '-canvas-background';
1 f# i* z6 A: A1 i& ?var obackground = this._oelement.parentnode.insertbefore(canvasel, this._oelement);7 a- M) y9 [2 z% T: k, W: N
obackground.width = this._oconfig.width;
/ q8 |: k) m) |# ^obackground.height = this._oconfig.height;* q# b9 K$ z' a% Y3 Z
obackground.style.width = this._oconfig.width + 'px';
$ P) X* N4 J. _obackground.style.height = this._oconfig.height + 'px';
6 X" {. |! T8 `! p5 l! b. B5 sthis._ocontextbackground = obackground.getcontext('2d');
9 |8 f# L7 P$ e6 i; Y};, C5 E' ]! H+ w" w# |# _* J$ c
canvas.element.prototype.setcanvasbackground = function(oimg) {
- R$ Y( a' X4 p2 hthis._backgroundimg = oimg;
+ j! i. v& l! t% @. v( V# gvar originalimgsize = oimg.getoriginalsize();
2 \7 ]5 a( p8 M/ U! Dthis._ocontextbackground.drawimage(oimg._oelement, 0, 0, originalimgsize.width, originalimgsize.height);
! k7 u8 e/ h+ d6 J};
! C1 h: x. [5 T8 C- j0 Rcanvas.element.prototype.onmouseup = function(e) {, t& P; E$ m9 Y# I5 q
if (this._aimages == null) {
) Y+ u& t5 [4 A, U& Dreturn;
! R1 Z$ r8 q4 S. a8 M. @7 J}8 L" g! S, U0 M9 Y
if (this._currenttransform) {5 B8 m& \1 Z2 \! X/ Y
this._currenttransform.target.setimagecoords();' I2 j; T; Y# r: H3 u8 i
}. s9 C1 K5 C7 E) R' @+ `. C9 S
if (this._currenttransform != null && this._currenttransform.action == rotate) {- n* S8 V, W' F/ @7 m
this.onrotatecomplete.fire(e);
! S: `* e* {3 v0 k! w- C$ T; {} else if (this._currenttransform != null && this._currenttransform.action == drag) {8 M9 P. N5 N; n# m
this.ondragcomplete.fire(e);
9 r0 `" b y. K3 A. e3 |' S}
6 D. ]( V, }- H$ y: b2 `this._currenttransform = null;
0 D' S n/ L# r1 X- o) S2 Fthis._groupselector = null;
: c. f( g7 P6 U7 K' E! Q/ Hthis.rendertop();7 n1 ~% g9 B2 Q; H6 s3 ]
};% x1 A& |+ \" M; _# x1 o( g" a
canvas.element.prototype.onmousedown = function(e) {
+ J4 f' Q5 `6 C* S; Z- H- v% b6 Gvar mp = this.findmouseposition(e);
0 @4 o# G2 M+ V% U. y! O( S$ P; eif (this._currenttransform != null || this._aimages == null) {/ o3 t% s3 _1 C! F8 D: U( S
return;
; C1 C$ |/ ]2 M3 ?# p}& L* E- {6 ^- i& h
var oimg = this.findtargetimage(mp, false);
- p8 g0 \, @% N N% M7 dif (!oimg) {
3 ?: _" }( f+ |( {7 `8 `6 R3 Lthis._groupselector = { ex: mp.ex, ey: mp.ey,
& C. P5 d3 k% T, m& c- n1 _top: 0, left: 0 };
! G# ]3 u7 |3 ?* i2 Q. t9 F}7 a. m8 Z7 k* H
else {
! X9 E* V3 b3 |% Ovar action = (!this.findtargetcorner(mp, oimg)) ? 'drag' : 'rotate';
; F) Z8 M# I2 jif (action == rotate) {8 n3 s6 j$ B: ?' X& {; X. M9 h$ {
this.onrotatemove.fire(e);# O0 g9 I! O9 E- v; T
} else if (action == drag) {+ N( z% _: q) Y8 ^9 o
this.ondragmove.fire(e);
* y- H6 s9 @$ B1 j}
6 ]) k) i1 T# S* r, Lthis._prevtransform=this._currenttransform = { 3 s b- M, O! w8 T5 {
target: oimg,
; J' I4 L& R6 v, h* X2 V( \9 U9 ?2 a w/ Oaction: action,
; v* N- g- Z' i0 S0 Uscalex: oimg.scalex,$ J0 _+ |' {' _. u8 Y8 t/ H
offsetx: mp.ex - oimg.left,2 h! E( X& J5 D1 g ?
offsety: mp.ey - oimg.top,
' [$ P4 x0 F/ r- nex: mp.ex, ey: mp.ey,
z7 e: X7 b& Jleft: oimg.left, top: oimg.top,4 E# i" o! K1 p3 |
theta: oimg.theta 5 ^( Z: M9 E& P. y9 A4 K
};
7 a% ~/ f- f, t/ Z: @$('canvas_menu').style.transform='rotate('+oimg.theta*180/3.14+'deg)';5 o; z) v4 M. M4 L% z- V6 e1 f
$('canvas_menu').style.left=oimg.left+px;
/ a2 Y& e; x2 C2 h! I9 t1 j. s! f$('canvas_menu').style.top=oimg.top+px;
. b7 ?, d- o0 |, q+ W" {7 G' W$('canvas_menu').style.display=block;, F$ J9 o- v S0 H# B9 E/ H* M$ i
this.renderall(false,false);
, r' q( Z. d8 Q}1 [6 e B" q7 H% n
};
9 A; j0 W0 a5 l; s3 q' `" gcanvas.element.prototype.onmousemove = function(e) {
' _3 [: v! |$ k3 \' zvar mp = this.findmouseposition(e);1 Y1 l$ L$ m) C& g7 [
if (this._aimages == null) {
2 ?4 m: c( D* t' d' h; ireturn;$ l+ ?. Z+ k$ B, R5 ]3 P
}
6 W) V! g7 l* N6 `+ G( A8 _+ gif (this._groupselector != null) {& J& f( Q1 K0 a4 E
this._groupselector.left = mp.ex - this._groupselector.ex;
- Z* P% |& |2 u- ~this._groupselector.top = mp.ey - this._groupselector.ey;+ C4 A: [, [4 G' K5 c) ^ T
this.rendertop();, @0 e G$ o5 \! O9 u9 ^$ `9 `
}
' I* D- T+ q" Eelse if (this._currenttransform == null) { p' t3 F( X: n# M1 x3 h; ]
var targetimg = this.findtargetimage(mp, true);4 K* \1 q7 F' T) r9 S1 A7 C$ q
this.setcursor(mp, targetimg);" l( b; F5 F. I' G. a0 }
}6 K" ^! ]1 g" |9 L
else {9 l4 M( U' M; j3 j2 K
if (this._currenttransform.action == 'rotate') {
7 m$ s8 [# ]7 U! K& q tthis.rotateimage(mp);
% L0 K& b9 A9 Gthis.scaleimage(mp);: F6 x! m. L+ F: z' a
this.onrotatemove.fire(e);
. E6 k/ X* k) C# c: c: A% R& u6 l' ^} ; ]2 m9 |' N# y4 }( ~, z& F5 A+ K
else {& \& J/ L7 `- p7 H2 O
this.translateimage(mp);! T. d% N$ W4 n/ _& O: z
this.ondragmove.fire(e);
% c+ ~/ L3 P, z+ _2 d* M; x1 J8 C}
! e/ Z) V* f) i3 r- {$ f! Uthis.rendertop();
' h& D$ M: H* u* k6 u$ K9 t} 0 p$ F6 \2 _* U* y/ h9 s: C# g
};
" Y5 d- U( k P: C! rcanvas.element.prototype.translateimage = function(mp) {* N2 `& N& U: D& ?
this._currenttransform.target.left = mp.ex - this._currenttransform.offsetx;7 W/ c0 B! b% `! d4 G
this._currenttransform.target.top = mp.ey - this._currenttransform.offsety;
( w* Y+ t+ X0 E$('canvas_menu').style.left=this._currenttransform.target.left+px;
3 Y6 I( L# c7 _, y3 m0 a$('canvas_menu').style.top=this._currenttransform.target.top +px;
5 V; K9 s7 t: J5 q};! A( d4 c: t8 U+ P9 x2 Z4 g
canvas.element.prototype.scaleimage = function(mp) {! L! b2 |5 M& y- v( ]7 Q7 \% l
var lastlen =
+ W+ f% w/ d }2 S' ^ O+ e) Jmath.sqrt(math.pow(this._currenttransform.ey - this._currenttransform.top, 2) +: B0 D! X5 V; E6 o% l5 ?+ M2 H6 m
math.pow(this._currenttransform.ex - this._currenttransform.left, 2));
1 V' o B/ ]- z! n+ K5 m" g5 Evar curlen =
- z: V& p; m. Z( cmath.sqrt(math.pow(mp.ey - this._currenttransform.top, 2) +
{# b! x3 L7 d$ ^ j4 h% A- ?. Tmath.pow(mp.ex - this._currenttransform.left, 2));+ W8 N9 s. w0 B. A
var curscalex= this._currenttransform.scalex * (curlen / lastlen);
: x0 X6 a, S5 v6 \" [var curscaley=this._currenttransform.target.scalex;
# b! H$ \) s f$ p- c, Mif(curscalex>0.7&&curscaley>0.7){9 x( h6 M2 w% B; x8 S Z! }
this._currenttransform.target.scalex =curscalex;
7 p: j, @5 A- p% y1 S( o0 }this._currenttransform.target.scaley = curscaley;
5 X3 ~' O& V' X}) z4 W% O% n1 ]
};$ m, ^ _: Z, _
canvas.element.prototype.rotateimage = function(mp) {
4 v" W' Q) a$ m% R6 cvar lastangle = math.atan2(
; J* ?0 S5 W0 r5 O$ u6 zthis._currenttransform.ey - this._currenttransform.top,
1 e( }! `8 @) G/ L2 y! q8 x$ r$ h& P" fthis._currenttransform.ex - this._currenttransform.left
& | c) t7 ~/ V1 [);) L) u6 c2 C0 v, d5 }
var curangle = math.atan2(6 F$ V# H1 |# f" h8 ^" D4 y
mp.ey - this._currenttransform.top,; v* `- r& v/ E
mp.ex - this._currenttransform.left( v! f0 O* |8 [
);7 s8 ?6 }$ X @" H2 w* o+ X
this._currenttransform.target.theta = (curangle - lastangle) + this._currenttransform.theta;; Z$ |% q' D% o
this.curangle=this._currenttransform.target.theta*180/3.14;
1 v, m3 |: M4 @8 A$('canvas_menu').style.transform='rotate('+this.curangle+'deg)';+ Z3 c" E. u( P! V+ R
};
- M) B3 |1 j+ ^0 U" zcanvas.element.prototype.setcursor = function(mp, targetimg) {
0 s! U+ K# l$ [% A1 `if (!targetimg) {
. e' o1 D$ ~) o/ D, y ?1 D; a" tthis._oelement.style.cursor = 'default';2 f) g; U0 b: r. Y( {, P a; V
}
/ }8 ~8 |8 B3 o. d7 ~else {
) o8 s$ L" }3 R. U# ^# X- Ivar corner = this.findtargetcorner(mp, targetimg);
: S8 a& w' i/ ~# ~if (!corner) # Z: l9 j0 D6 ^, Y
{+ `8 x, B* G. R& C7 c
this._oelement.style.cursor = 'default';
3 m5 \# G( `- a" w- j}
8 I( J$ y8 k8 I' ~8 B/ felse
0 X) N% q) X5 X' D E# s9 j{
" J. b0 S9 h/ r" y& ~0 |if(corner == 'tr') {7 T# q% q3 c; N* ~ a
this._oelement.style.cursor = 'ne-resize';
1 l8 Q* T! W# F, F/ m4 p N, r}
* G; {7 e0 M( p, H3 P, O2 R5 M! D5 Ielse if(corner == 'br') {) B' {. n2 _/ e5 h4 K
this._oelement.style.cursor = 'se-resize';3 t# n' E" E. N: y
}6 P. `2 ]- c) S% L* f
else if(corner == 'bl') {" h' _# B6 W w4 U( |- {1 M
this._oelement.style.cursor = 'sw-resize';
$ A5 e+ ~: J* l. x6 G8 M}
: a$ O3 M$ c3 i f7 zelse if(corner == 'tl') {
" n6 n# Y. Y3 Athis._oelement.style.cursor = 'nw-resize';
; n8 R) W9 B! c4 x+ H}
7 z% _! X' P. a; A' W. |' Pelse {5 F+ _: Y7 [; m D. j
this._oelement.style.cursor = 'default';
# Z9 f/ n# u3 R5 t# @: B5 c}
' a9 k N2 A8 ?- Q7 A. z: k}% n* D) v) v( [( y: g1 _
}' Z7 D! r9 J) D' U r |+ [
};: T0 ~, O7 B6 s, t
canvas.element.prototype.addimage = function(oimg) {
& V1 A: K/ p0 e9 m7 `- l2 H8 ^* ~4 Aif(s.isemptyobject(this._aimages)) {
+ i! g( c- L8 t) ]8 w0 Qthis._aimages = [];5 y" }- u1 [! Y9 I' P% v
}
; R. V* g% [' ~this._aimages.push(oimg);
4 k0 G+ H T( ithis.renderall(false,true);</p> <p> };
$ z: [: t5 Q5 V) Tcanvas.element.prototype.renderall = function(allontop,allowcorners) {
0 ~' l' n$ R, [ v* T4 U K& R# _var containercanvas = (allontop) ? this._ocontexttop : this._ocontextcontainer;
! n* [" A: w/ O' D4 ]this._ocontexttop.clearrect(0,0,parseint(this._oconfig.width), parseint(this._oconfig.height));/ W* l" P9 l: j; G7 S. V
containercanvas.clearrect(0,0,parseint(this._oconfig.width), parseint(this._oconfig.height));
2 g+ j4 j( o0 `( m) [if (allontop) {3 k* _$ b' e, @$ Z; R1 w
var originalimgsize = this._backgroundimg.getoriginalsize();
; w# B* K2 Y- x# T6 @0 U8 rthis._ocontexttop.drawimage(this._backgroundimg._oelement, 0, 0, originalimgsize.width, originalimgsize.height);
, h: q5 Y+ t. m1 C}
* P( w7 w+ E V* I: @4 R/ p! Kfor (var i = 0, l = this._aimages.length-1; i < l; i += 1) {6 r9 I! v4 i" W0 [) x
this.drawimageelement(containercanvas, this._aimages,allowcorners); , ~) j* \ Y' j& c
}! k) y% e0 R0 p, U* Q
this.drawimageelement(this._ocontexttop, this._aimages[this._aimages.length-1],allowcorners);2 o. w+ ^1 B- h- \7 ?( U1 X
};
* `- t) l Z f, R$ Vcanvas.element.prototype.rendertop = function() {
8 g0 z3 O9 U+ E4 x1 t; A4 Bthis._ocontexttop.clearrect(0,0,parseint(this._oconfig.width), parseint(this._oconfig.height));; T: T; j2 f- [+ X
this.drawimageelement(this._ocontexttop, this._aimages[this._aimages.length-1],true);" y8 e. \. U1 K& g( v3 g. n2 @# l
if (this._groupselector != null) {
- j' ]" m- r( x3 }3 a& w! [5 Gthis._ocontexttop.fillstyle = rgba(0, 0, 200, 0.5);$ ^; D9 d" V6 @1 a3 K
this._ocontexttop.fillrect(
, r! V3 v8 Y0 \, Z6 i/ V3 Sthis._groupselector.ex - ((this._groupselector.left > 0) ?
. z9 {2 l) W4 W7 D; o0 : - this._groupselector.left),
' x) Z% h" r5 Q h2 H2 Hthis._groupselector.ey - ((this._groupselector.top > 0) ? 0 V. C& V. L5 ?* G, I! i) X
0 : - this._groupselector.top),
* S8 `% M, V& G# kmath.abs(this._groupselector.left), , D. l% k& h' g1 N) |8 Q& t" W3 F
math.abs(this._groupselector.top)
1 M0 X! {( a/ |! w);
; D7 L( k+ A# g2 ?3 j& ^2 tthis._ocontexttop.strokerect(2 o; i+ R" l+ k4 U
this._groupselector.ex - ((this._groupselector.left > 0) ? 0 b6 i5 ~5 |. W4 R
0 : math.abs(this._groupselector.left)),
6 t; x: ~! B5 T$ ]this._groupselector.ey - ((this._groupselector.top > 0) ?
+ X9 a" r3 i0 c, h j2 D0 : math.abs(this._groupselector.top)), 8 u$ n; c. ^6 [( n8 Z6 ~
math.abs(this._groupselector.left),
6 p+ D E& f- w4 b0 [math.abs(this._groupselector.top)) _, W- f7 ?4 R, q+ M) n5 s
);; q. B- Y, \& S" k, l9 W
}
8 _' D: D. F3 }( T; A$ b};
& d/ @9 S' p7 vcanvas.element.prototype.drawimageelement = function(context, oimg,allowcorners) {1 `' x$ k' M; a0 B
oimg.cornervisibility=allowcorners;3 j. M- |8 @/ C- n) z/ B
var offsety = oimg.height / 2;
' B; g9 {7 g# w2 A6 ovar offsetx = oimg.width / 2;
0 y: e) _% J9 U, _( dcontext.save();! m- \7 L+ e; _: V- A8 `) { {
context.translate(oimg.left, oimg.top);
4 Y7 P+ J( k' ]2 N7 n1 _. _3 Ncontext.rotate(oimg.theta);. g- `. M' b0 ?3 x
context.scale(oimg.scalex, oimg.scaley);
0 u7 B- C$ H! ?/ M- I+ mthis.drawborder(context, oimg, offsetx, offsety);8 K: I7 _/ A0 w( s! }/ ?
var originalimgsize = oimg.getoriginalsize();
# b& N* J+ h+ o" C" L. g% t6 vvar polaroidheight = ((oimg.height - originalimgsize.height) - (oimg.width - originalimgsize.width))/2;9 b e3 R8 s3 |8 B& t
context.drawimage(
8 u7 H# i m) @$ L& k7 a: Yoimg._oelement, / c- s. z0 C0 Z
- originalimgsize.width/2,
9 @. X$ N8 G# q0 X, Z# L' g9 ^((- originalimgsize.height)/2 - polaroidheight), 9 k3 |7 D* R; R2 E. S
originalimgsize.width,
% [7 w& @; T: l* q& L1 }/ eoriginalimgsize.height+ F1 D" D7 o/ x
);
* o! `) r0 T) I/ Wif (oimg.cornervisibility) {
7 W7 ]- C- J3 Xthis.drawcorners(context, oimg, offsetx, offsety);" o8 @! K u) \+ o* L$ H& O
}
0 ]" H( [) b+ `- b$ a! _context.restore();8 Q( l* q, R8 U) s9 r# [& g6 o
};
3 @2 o% A5 w' {canvas.element.prototype._getimagelines = function(ocoords) {+ P1 Z0 u1 g" f0 p6 H
return {" x+ n- H3 P' n* e) s
topline: { % S7 L! [( Y. a2 a9 F: |+ I4 e1 P* m
o: ocoords.tl,
4 R* u! s0 }- Rd: ocoords.tr
3 g# b( @% }) \2 Y# R0 r},. ?- S# X# i: q" `
rightline: {
O2 Q& H8 X Y' Do: ocoords.tr,6 d0 U/ _ F4 J& j
d: ocoords.br & R$ I5 _# X; p2 C( A4 y
}," V5 h6 I+ v. b. z- a+ q
bottomline: {
# T( T. P: u; }" ]o: ocoords.br,! O( Z+ S4 V3 H; d3 _
d: ocoords.bl
0 V( R- Y4 W. Z: ^& @}, k& W7 S3 `2 B3 V' C- Y
leftline: { # [) y# ^3 F9 k3 t) t4 \3 o
o: ocoords.bl,, D# X8 N$ F+ ]% d6 h
d: ocoords.tl 6 E( n4 {: M5 K1 x& ~: M: B0 _
}2 l* n( K1 T, R' [# |6 E* I; }$ t
};
! D4 n( ~' d Y1 }' a};
$ M8 b" U% W5 B" ecanvas.element.prototype.findtargetimage = function(mp, hovering) {7 _% [+ J* }' k0 p+ M
for (var i = this._aimages.length-1; i >= 0; i -= 1) {$ N1 U" a! o y) W s7 y$ J9 l# d
var ilines = this._getimagelines(this._aimages.ocoords);; M: _0 n9 ~8 x- m! f
var xpoints = this._findcrosspoints(mp, ilines);' \) D" b: S2 m% d; }
if (xpoints % 2 == 1 && xpoints != 0) {
8 \" D: ]% n5 P4 t$ T( rvar target = this._aimages;/ [8 i( o# T. ?, r6 Q
if (!hovering) {
. P& {0 S8 H* A6 a0 w+ @: W* Uthis._aimages.splice(i, 1);
5 l8 {# t3 u9 s0 H I/ W7 ithis._aimages.push(target);
; p+ u" D- E0 k5 m( ?}) J8 i0 k2 X% b6 V
return target;/ h' }1 \6 Z5 T2 ]
}
7 v0 Y- }/ ^ E8 M5 y7 X3 R8 z. A}9 _5 ], p6 W1 F
return false;' V/ y, K- Q) w: L
}; # q+ P6 O, A; D5 Q
canvas.element.prototype._findcrosspoints = function(mp, ocoords) { P% D; d9 m$ @. {" M3 T
var b1, b2, a1, a2, xi, yi;3 @3 U) H; _6 L7 e( z# B& B
var xcount = 0;
' m. Q2 z: W& x9 a' Qvar iline = null;
2 L% \) V+ |" c. Gfor (linekey in ocoords) {
' U2 e' ~2 `. Y8 `; iiline = ocoords[linekey];: `. |' O$ ]( ]3 o1 x6 Z
if ((iline.o.y < mp.ey) && (iline.d.y < mp.ey)) {
, ~, q8 T: g! T' s1 J: ~! B |continue;
0 H* {+ p! l! A8 w$ u}
( I( F7 q+ U+ N2 ]% x0 i; Cif ((iline.o.y >= mp.ey) && (iline.d.y >= mp.ey)) {0 z" X. S5 I1 G1 W' I, P: e
continue;# V( d0 h4 b! R# ~. ?; u' |
}+ x+ i4 {% {0 X0 v! h
if ((iline.o.x == iline.d.x) && (iline.o.x >= mp.ex)) {
8 R7 V) L- e: r \* Sxi = iline.o.x;
# J, f3 U2 B3 q Syi = mp.ey;
- Q) k+ A1 l! }}7 y7 W0 Z$ H" }
else {4 r ~% }% W8 v
b1 = 0; 7 g4 B* N" U. R+ }' x6 `
b2 = (iline.d.y-iline.o.y)/(iline.d.x-iline.o.x); 5 M/ n* Q6 J: h4 o
a1 = mp.ey-b1*mp.ex;7 k! L4 {9 V) B/ F' J9 _% S
a2 = iline.o.y-b2*iline.o.x;
7 e( U- X. c! \ Gxi = - (a1-a2)/(b1-b2); . B& U0 a! K" _6 c! f
yi = a1+b1*xi;
- J* |" p3 I K+ H `* ~} D3 u+ h, V& a, H4 c
if (xi >= mp.ex) { 4 B' V4 w: P* [ ~7 e m
xcount += 1;
+ `. j, D/ n7 M4 \& x9 I- T' C}1 [' T ~$ x3 q* Y& I1 T( d
if (xcount == 2) {
6 U' Y/ n* o( R. h# H) s8 |* dbreak;
0 j5 _& p3 L Q5 {4 `9 ?}
5 I8 q% k, s" q}
- m& j" f2 a/ ^& }, S ?' ureturn xcount;4 S# j8 {0 F/ i* F
}; w# {" H2 i0 h l# j6 U
canvas.element.prototype.findtargetcorner = function(mp, oimg) {
0 {/ s% v# y& Vvar xpoints = null;
' h( A2 Q" x G- X8 s: V8 |. Pvar corners = ['tl','tr','br','bl'];( f; M# |% j% h- W2 g- X
for (var i in oimg.ocoords) {
4 X! z. l8 i" |7 g. O5 gxpoints = this._findcrosspoints(mp, this._getimagelines(oimg.ocoords.corner));
! g! r. J0 s+ k9 Cif (xpoints % 2 == 1 && xpoints != 0) {) g- }+ @ G0 s( T. O6 E
return i;
6 V* `6 a( w1 f9 q9 v, k}
3 Z. l$ `% ]+ {5 c. W6 j; a}! z6 J" p2 Y/ ? o
return false;8 [- U3 g; c3 k6 v% b8 B$ t
};- q$ b: a3 A" K* k) \; e
canvas.element.prototype.findmouseposition = function(e) {, f1 R5 m- k. o$ g+ W
var parentnode = (e.srcelement) ? e.srcelement.parentnode : e.target.parentnode;) w4 t+ S/ v- V3 }
var issafari2 = !s.support.ie&&!s.support.firefox;
, M( N" E% ?) p: o4 d' pvar scrollleft = document.documentelement.scrollleft || document.body.scrollleft;
5 h+ i, q7 |- c. }$ i$ Dvar scrolltop = document.documentelement.scrolltop || document.body.scrolltop;
0 n# z: w8 V- g6 k6 _) xvar safarioffsetleft = (issafari2) ? e.target.ownerdocument.body.offsetleft + scrollleft : 0;# [, ?. a5 C6 s W* q
var safarioffsettop = (issafari2) ? e.target.ownerdocument.body.offsettop + scrolltop : 0;
3 o: W# E3 G# U2 Preturn {
: [9 n. J* I9 b- K3 `% }' jex: e.clientx + scrollleft - parentnode.offsetleft - safarioffsetleft,
; g/ ~/ t( N; t aey: e.clienty + scrolltop - parentnode.offsettop - safarioffsettop,! W7 e$ P. Q/ V( r9 E
screenx: e.screenx,
1 E9 l) O& r; }8 O+ N. Xscreeny: e.screeny
) ? F5 A+ h* g};
& h" \! b. W1 p/ O9 Z0 b1 g};; G, k9 Y0 v+ f8 p# G4 J! R
canvas.element.prototype.drawborder = function(context, oimg, offsetx, offsety) {
# k# d( P3 q9 e9 a8 b% w( tvar outlinewidth = 2;
0 T) ^+ f' Y' F- S" X3 Jcontext.fillstyle = 'rgba(0, 0, 0, .3)';: f! F- U6 j4 [8 M" v! y6 I
context.fillrect(-2 - offsetx, -2 - offsety, oimg.width + (2 * outlinewidth), oimg.height + (2 * outlinewidth));
, M$ b1 E9 e3 \$ Q9 L% k( Bcontext.fillstyle = '#fff';% c& {. S* Q" T2 l( a: ~
context.fillrect(-offsetx, -offsety, oimg.width, oimg.height);
) `5 G2 W% a4 `" c};
+ i2 N5 X, f1 Q* o0 Ccanvas.element.prototype.drawcorners = function(context, oimg, offsetx, offsety) {
x' {6 E; |$ c# ~9 [: X# x9 I, n! zcontext.fillstyle = rgba(0, 200, 50, 0.5);$ R0 M4 @! | S8 {) K1 k( P
context.fillrect(-offsetx, -offsety, oimg.cornersize, oimg.cornersize);
* j; K( @2 P9 C/ [9 Ycontext.fillrect(oimg.width - offsetx - oimg.cornersize, -offsety, oimg.cornersize, oimg.cornersize);# z) I* u* H$ t* T. Z
context.fillrect(-offsetx, oimg.height - offsety - oimg.cornersize, oimg.cornersize, oimg.cornersize);
2 @3 r& o0 l; @: Y5 ncontext.fillrect(oimg.width - offsetx - oimg.cornersize, oimg.height - offsety - oimg.cornersize, oimg.cornersize, oimg.cornersize);/ u8 u' [' R H5 v0 E
};- ]! ]' W8 z3 I% q( }; j& d& |
canvas.element.prototype.clearcorners = function(context, oimg, offsetx, offsety) {
" d+ H# V* U5 y- e- b' {1 B7 [! Lcontext.clearrect(-offsetx, -offsety, oimg.cornersize, oimg.cornersize);
1 N( e, F2 Z3 H/ H7 Pcontext.clearrect(oimg.width - offsetx - oimg.cornersize, -offsety, oimg.cornersize, oimg.cornersize);
- y5 a# z9 J1 ^- fcontext.clearrect(-offsetx, oimg.height - offsety - oimg.cornersize, oimg.cornersize, oimg.cornersize);
: y1 `/ v( m& U( ]: Kcontext.clearrect(oimg.width - offsetx - oimg.cornersize, oimg.height - offsety - oimg.cornersize, oimg.cornersize, oimg.cornersize);
( I0 Q2 U ?" w) c8 S Zcontext.restore();/ {; r q8 w: Z9 s5 M
};" W7 O) _( ]! S+ @
canvas.element.prototype.canvasto = function(format) {3 {6 D9 o% r u0 q
this.renderall(true,false);8 f* o& S( ~: ?# b! K
var containercanvas =this._ocontexttop;# _+ k8 j1 f& K- p4 Q: c( e1 l; G
for (var i = 0, l = this._aimages.length; i < l; i += 1) {/ u& R5 b0 ^5 a; R8 H- U' C
var offsety = this._aimages.height / 2;
% Z9 J8 q% H6 |, T, w Avar offsetx = this._aimages.width / 2;6 o6 Q% f$ |" c7 ~2 ~9 @
this.clearcorners(containercanvas, this._aimages, offsetx, offsety);2 Q3 }; G. z: o; G5 y
}0 Y' E* s I P) d% d3 \
if (format == 'jpeg' || format == 'png') {) e: s/ J/ R% h @0 v
return this._oelement.todataurl('image/'+format);" ~% \$ x9 `. o( t0 l3 r
}; I' u$ Q, }1 _& z7 A2 G) w
}; $ ? U3 v# y- P, z& A
canvas.customevent = function(type) { e; t$ [6 Z. A0 r
this.type = type;, b! z; P7 S9 n `4 Z4 A. `" `- o: N$ Q
this.scope = null;
" C5 I+ i" { w& X. G- |; |6 [: ?; Qthis.handler = null;
& G, J) c* j' jvar self = this;
. {* n& b8 c/ {this.fire = function(e) {0 A- y" o1 x* J! h
if(this.handler != null) {
9 D' E D$ F" |% ?, o2 s' ?2 cself.handler.call(self.scope, e);
( r* P d7 w+ k, {$ ^}
# ~8 _0 C4 N# O4 C+ |};- z7 ~, a9 ^1 O: k" [7 [: v
}; - Y) `) C0 G) i
}());
* K% w( g2 o6 ^9 N& V* `/ `7 C" q0 qreturn canvas;
) S) [3 ]5 i# V: `& I5 U4 A* s});3 v% V# v( L% f7 p2 f
canvasimg.js代码如下:: }# {9 n' ?1 q* c" F0 d
复制代码代码如下:define('canvasimg', [ '../multi_upload/core' ], function(s) {) K- w3 x! c. @1 N }, A
var canvas = window.canvas || {};
; s, v( T9 V8 Z; J# C0 w(function () {0 b/ g5 _0 t1 m5 g R
canvas.img = function(el, oconfig) {
$ [8 y; j- ?( `9 V# k) ]( L+ [this._initelement(el);. p5 p$ P r5 x0 i7 s( t
this._initconfig(oconfig);9 \& k. ^- Z( [
this.setimagecoords();! M* d: Z) U/ V" _
};: l4 k3 R# {! I7 i8 ?, N( I" x( V
canvas.img.css_canvas = canvas-img;' c& X- `# o7 O$ w/ y! G7 p
var default_config = { ! p- G) H& V8 W# b1 D/ e
top: {
. [6 j/ h$ R5 Akey: top, : c$ O# {2 a K4 W
value: 10 0 R- D) c3 e3 {1 A9 n; b
},' j. h6 W) y9 L1 n
left: { ) n/ E: L' Y; h0 E
key: left,
. i6 N8 p0 {1 n. lvalue: 10* Z3 k E7 y$ d/ a% M& c
},
+ ]/ L0 W9 @ ~/ w( {% gangle: {
) p: c0 G( N7 ^! B7 hkey: angle, 8 _) H& e/ k+ e' d0 r
value: 0
+ j' W5 |7 O y% ?* }. ^},* K* p9 X- A8 A8 y6 d1 u. }8 ?
theta: {
$ p& u; C& \" ?! g! E C6 @/ Bkey: theta,
0 I2 Z8 h$ o$ s1 p1 q3 lvalue: 0 + w5 z( U& h3 w/ f4 ] `6 y
},' S" f' Q! \) f, G; I
scale-x: {
; }4 F" Q/ a' n _; C2 ?key: scalex,
( N* \# j+ ]' y) O. ~; `value: 1
* t6 g0 I5 j2 v$ {( `},1 z( P4 y$ |) m( N* A
scale-y: {
5 r7 Z" {+ V5 @# a! ]3 F0 ckey: scaley,
8 d# e, w% S+ Cvalue: 1
* I! R+ e9 Y! \2 K% Y; S},. K7 H. Y, A9 K; f6 F( K( ^
cornersize: {
0 \1 F/ I7 l0 Z8 L; @9 z+ skey: cornersize, 7 M m! j& X+ h) @( E
value:108 H: Q: B: E: ~/ V, e. |' }; `
},+ d% s7 g/ ]4 k; @' o
borderwidth: { $ U) o( n! M, u
key: borderwidth, * q" s* J) `. `5 `4 J2 ~
value: 10
/ ]5 J$ a5 Q& R) ]2 [6 E4 g},
' h0 ~( I* b9 o3 M* B2 Epolaroidheight: {
H+ \; F+ H) W8 m [1 U# x" |key: polaroidheight,
/ x- d1 m2 r; x; J: Rvalue: 40
2 Q `/ A3 _/ m+ A- X$ X},- o4 K/ t% @/ A$ s( o! l3 f
randomposition: {
: {& P9 E( K" S+ l) {key: randomposition,/ ^' l; W2 H: v) Y1 Z( p, n. r/ w O+ F
value: true
$ |" c: H: U6 q}
6 ^ a" P- |7 h1 | F& k};
6 o/ X) t- x0 Ycanvas.img.prototype._oelement = null;! K; d+ c0 \/ g$ E/ i% m) C
canvas.img.prototype.top = null;8 \$ y! }- q. ^) t
canvas.img.prototype.left = null;
5 g4 X. `. [( ucanvas.img.prototype.maxwidth = null;
$ d" ?5 g( a0 m! H5 k/ Y1 wcanvas.img.prototype.maxheight = null;, ~/ t* ~6 I, J6 O2 \+ e! k
canvas.img.prototype.ocoords = null;. x# ~8 S7 M U) } D% J4 x
canvas.img.prototype.angle = null;) `; V+ w1 ^5 N. ^, ~% A7 y9 \, A
canvas.img.prototype.theta = null;
/ R. @2 R6 e& I3 q2 pcanvas.img.prototype.scalex = null; v' D3 Z6 g* s
canvas.img.prototype.scaley = null;& l2 h1 H# u: I& C7 g* c
canvas.img.prototype.cornersize = null;: d. M; z& ]" }5 C- f
canvas.img.prototype.polaroidheight = null;
% p8 o5 f0 D+ ]" S+ _+ N! k9 P% vcanvas.img.prototype.randomposition = null;
9 C4 l' z% B3 wcanvas.img.prototype.selected = false;
3 z( S4 ]; Z6 |6 g/ m, S3 rcanvas.img.prototype.bordervisibility = false;5 G- s, K- ]+ c3 F) A; f/ {8 s, i3 y
canvas.img.prototype.cornervisibility = false;3 U* @9 R. q$ Z H5 j
canvas.img.prototype._initelement = function(el) {$ X% ]" D; q' N; B
this._oelement = el;7 O& J% f% {- o1 |$ j
};
, T0 r( V4 L* g& O+ icanvas.img.prototype._initconfig = function(oconfig) {, q8 y; ~$ u2 d( Z- p
var skey;2 O5 T) v- {9 ]+ M0 ?' x
for (skey in default_config) {* |$ z* f3 w$ s% t8 |4 C. g/ n' N
var defaultkey = default_config[skey].key;
# C: o# w- [% V- U. i9 bif (!oconfig.hasownproperty(defaultkey)) { // = !(defaultkey in oconfig)
5 P4 s8 _7 v+ B4 l' S) V. Dthis[defaultkey] = default_config[skey].value;
( C3 M8 _+ a4 R/ r: ^' O1 u8 N}
+ i! o7 p3 M% {, J& j" v; B4 K- M+ Delse {% e8 j& A) y7 ^6 P
this[defaultkey] = oconfig[defaultkey];2 \0 H' P; s; U
}6 G# W) T( b$ v# f( G9 s
}
! r5 h5 K% H, O) \# Hif (this.bordervisibility) {8 G _( j: I; B+ R; q8 Z @
this.currentborder = this.borderwidth;& {, N/ ~, l g/ h# s4 c
}
7 E* V$ |; @2 Y) Telse {
: R5 e* v1 n5 q- N$ Lthis.currentborder = 0;& S5 x& U2 F2 R4 t2 \
}
0 Q: Z) n! Y/ K/ Cvar normalizedsize = this.getnormalizedsize(this._oelement, parseint(oconfig.maxwidth), parseint(oconfig.maxheight));
/ Q, u" k5 V( r* Pthis._oelement.width = normalizedsize.width;
; J# Z: ^- ^5 g& n- athis._oelement.height = normalizedsize.height;
! C" V, C- ]+ @this.width = normalizedsize.width + (2 * this.currentborder);
+ ^; `( n; k4 zthis.height = normalizedsize.height + (2 * this.currentborder);& G2 t8 |- Z9 ]/ e* Y# @! @
if (this.randomposition) {
0 M8 `0 B0 v0 u" Wthis._setrandomproperties(oconfig);
& `9 o" v" e. C4 \2 B; U, ]1 Q}
) E# b+ W- L, Dthis.theta = this.angle * (math.pi/180);) d- g4 g/ f5 m3 R2 M( U" }) E
};- \6 P* N0 X/ o7 A( T _; ? V
canvas.img.prototype.getnormalizedsize = function(oimg, maxwidth, maxheight) {
, |: g& _* c4 u& D2 Z: a( Eif (maxheight && maxwidth && (oimg.width > oimg.height && (oimg.width / oimg.height) < (maxwidth / maxheight))) {4 j v$ p# i/ k& r% E! ^
normalizedwidth = math.floor((oimg.width * maxheight) / oimg.height);
( D! q% R; x! K) ]5 C- Onormalizedheight = maxheight;
5 j/ d+ \3 |* I}/ i1 V' ^3 a" f' G2 {* q
else if (maxheight && ((oimg.height == oimg.width) || (oimg.height > oimg.width) || (oimg.height > maxheight))) {3 p+ e3 a6 Y9 _% i7 w
normalizedwidth = math.floor((oimg.width * maxheight) / oimg.height);7 e( ]! J6 p0 Z) \( g4 @$ Z
normalizedheight = maxheight;8 T( V9 i$ J/ l6 }5 \5 K8 ]
}
5 |' u. x; `" x2 P& |7 nelse if (maxwidth && (maxwidth < oimg.width)){
+ z. s% U2 \% U/ bnormalizedheight = math.floor((oimg.height * maxwidth) / oimg.width);
3 I% ]' E+ T. D2 N! R4 Jnormalizedwidth = maxwidth;
. O( L* `0 I% |/ @! J}
8 \: {8 E- e! z2 ~3 e- nelse {! v. U2 P# `, }2 b
normalizedwidth = oimg.width;
' t7 C) J1 R$ N2 q4 J+ w- u9 rnormalizedheight = oimg.height; ' V4 m, X9 G( g0 o+ t
}
9 P, v% B( ^8 L" m- L! Areturn { width: normalizedwidth, height: normalizedheight }
& F4 s+ p3 z/ X9 s; Y! v* u},; H, Q" P5 _8 f
canvas.img.prototype.getoriginalsize = function() {
+ C0 s, I( P2 J4 `8 U' j7 Hreturn { width: this._oelement.width, height: this._oelement.height }
: F7 j7 L3 _) ]( Q, O$ |};" L+ L3 b1 a7 T3 [+ q, K
canvas.img.prototype._setrandomproperties = function(oconfig) {; m. d$ i1 \. V" X$ Q% Y$ e |
if (oconfig.angle == null) {
2 ~ Y8 {4 H. e. K) W1 S& j7 ythis.angle = (math.random() * 90);# C. h1 W o. v! v8 N$ a: J+ {
}
( B) Q1 \8 v4 g' q0 [3 K9 `if (oconfig.top == null) {
( ]5 L8 M8 P1 [this.top = this.height / 2 + math.random() * 450;
$ P$ Z* n+ J' B6 b8 N# n' P}( C- ~0 j7 H4 y1 Q! B
if (oconfig.left == null) {; v# V* I3 k9 `$ L
this.left = this.width / 2 + math.random() * 600;% n2 L# W3 K" j* _; h2 p, F& v
}
# M5 J. O3 g' d( P9 ]};
0 a) h7 n' a" [, x$ e- icanvas.img.prototype.setcornersvisibility = function(visible) {, u7 d8 z5 t3 N' h3 [
this.cornervisibility = visible;- C8 X- S0 ^" L# @- R
};
% x* o! w6 O4 Vcanvas.img.prototype.setimagecoords = function() {( [4 g: c2 T+ x; ^ G) j. A
this.left = parseint(this.left);' `( z) @5 O3 g* s2 R* p0 }
this.top = parseint(this.top);
' P$ W8 A- |$ Xthis.currentwidth = parseint(this.width) * this.scalex;) ~+ E/ J6 G) ^$ u
this.currentheight = parseint(this.height) * this.scalex;
2 X' ?6 ?$ \" g. H$ Q6 rthis._hypotenuse = math.sqrt(math.pow(this.currentwidth / 2, 2) + math.pow(this.currentheight / 2, 2));
# L' r, Q! D4 m( R- J' {# v8 Zthis._angle = math.atan(this.currentheight / this.currentwidth);) z4 n# E7 Y8 [7 M
var offsetx = math.cos(this._angle + this.theta) * this._hypotenuse;
( G) v- B2 C6 @: n: Wvar offsety = math.sin(this._angle + this.theta) * this._hypotenuse;6 z4 G/ ^& o, w
var theta = this.theta;
! K3 J4 l+ @$ Q7 e8 B0 f. i5 Bvar sinth = math.sin(theta);0 N1 U0 v- J" M$ j8 N" y7 z
var costh = math.cos(theta);5 Q+ ~- G7 g, G0 X& v
var tl = {( e, c8 W9 O) L5 |: n% W
x: this.left - offsetx,0 P1 r( s$ j' A! \0 l2 z
y: this.top - offsety2 L b& c8 ?5 R0 L6 r1 x
};4 \% @ _' C, O# L* Z& V
var tr = {
( U1 A# W( M/ s) \6 z* Lx: tl.x + (this.currentwidth * costh),
6 y4 R9 V0 l% T; s$ W9 |y: tl.y + (this.currentwidth * sinth)8 F/ o/ n9 P8 B% x* e& g# d) c
};
! p3 S4 W. X7 n$ Uvar br = {& t# ?: _! H/ x; Q; n% O0 \
x: tr.x - (this.currentheight * sinth)," `* w; K9 `& a: E
y: tr.y + (this.currentheight * costh)8 O6 F+ r+ Y) W7 i4 ^6 Z) }9 W3 k
};9 P0 k7 p% u' d- |/ }% W9 l2 o
var bl = {
% d1 R' Z5 ]0 W" I4 ?+ ^0 qx: tl.x - (this.currentheight * sinth),7 Z4 n/ _9 ~1 N6 C: m
y: tl.y + (this.currentheight * costh)
% F& v9 @2 L% K( l6 Q2 T: W};
, M6 o% a( {* F" q7 P) gthis.ocoords = { tl: tl, tr: tr, br: br, bl: bl };
3 h5 X1 O- [1 ~. jthis.setcornercoords();
: `6 p- k0 u7 J- N+ `7 X};
" h X" V! f k( |, Ucanvas.img.prototype.setcornercoords = function() {
/ T( s. }$ ~. Z8 L+ t+ w! hvar coords = this.ocoords;+ y G i+ Q3 Q# c! E
var theta = this.theta;
% [% T% J3 l7 Z* rvar cosoffset = this.cornersize * this.scalex * math.cos(theta);1 h5 K. }2 D0 d V; J
var sinoffset = this.cornersize * this.scalex * math.sin(theta);* w# [% Y- B2 i" \ E
coords.tl.corner = {$ y$ H$ L4 i8 A
tl: {7 o5 P1 f" p2 U O
x: coords.tl.x,: i% F% G W/ E. z
y: coords.tl.y7 O8 `7 [0 K U7 [4 o. y
},, W. [, B3 Y8 G0 Y8 B
tr: {% A' V3 C/ T- y& j/ Q5 m2 c$ p
x: coords.tl.x + cosoffset,
9 i9 t3 ]6 y7 Q. d2 \" R8 @- dy: coords.tl.y + sinoffset
o. V: U- M( E# U; l' c' D! M},
8 Z) a/ u% U* V# H0 fbl: {. T/ N0 D% c/ ?$ n3 F
x: coords.tl.x - sinoffset,
]- o9 N& s: X9 H* D; ?y: coords.tl.y + cosoffset: z* k4 j7 H" h5 _
}: x2 {, O; [" T5 {! A
};3 `+ h: n( j2 q# e# ~; D4 e
coords.tl.corner.br = {0 |. ~4 D% ?$ v& V0 p& z& r
x: coords.tl.corner.tr.x - sinoffset,
E- h1 m0 X: I# o3 Wy: coords.tl.corner.tr.y + cosoffset
% l8 Y, W* f/ g& d# A" `};
) Q, ~0 s( C+ \4 X5 ?4 ^coords.tr.corner = {# {; f+ Q. |4 r; n) x& ^) m
tl: {
" M! v+ ?2 s8 px: coords.tr.x - cosoffset,& K6 K" Q( [7 H9 w3 I: w1 ?
y: coords.tr.y - sinoffset) h4 G2 J! J: d8 }& [
},% G" w: M, C% Z, Z7 Y }8 t+ @+ {
tr: {5 I: } R/ T( H* A( p
x: coords.tr.x,- m/ S& O) i8 X* w
y: coords.tr.y
# j: I6 c& l5 w7 Z! u. q' ^' S- v},! f# G8 | o% s! C& P; B' b( K# Z3 N
br: {
/ L0 ^4 I. j! t# C6 ]3 Gx: coords.tr.x - sinoffset,% R( P- L% ~: {. u" o
y: coords.tr.y + cosoffset. c3 O w0 A: x c
}/ `" M2 G4 c. b* e1 d' x% }
};
: L- t5 Y" s, }* b. i, mcoords.tr.corner.bl = {
" B+ Q w) _. q& l# ~x: coords.tr.corner.tl.x - sinoffset,% M. H. m% I( d6 v4 a0 o7 A1 w( a
y: coords.tr.corner.tl.y + cosoffset
6 O5 E5 A- W8 u L/ x};2 o7 Q, E% n4 Z9 B- n; y
coords.bl.corner = {
5 g$ y* D! ~* h. d' T- gtl: {* y" \0 D( ]3 v4 u7 p1 J1 D. U
x: coords.bl.x + sinoffset,+ m4 n- g. O+ I: w. [/ A
y: coords.bl.y - cosoffset
& a/ z% x* Q1 [/ j- B},9 a- o$ t" \9 i0 V0 o
bl: {
0 G( m; I9 ~ ]x: coords.bl.x,3 t" J7 x. r. L, u/ h! q
y: coords.bl.y
Y" V* X: ~% C% H},
4 R$ e9 _: I b( B) O# G( q7 Ibr: {
* R3 s l% H" E `# N; [9 Hx: coords.bl.x + cosoffset,
; \4 c! l/ l) s/ q2 W1 {& c# h! Hy: coords.bl.y + sinoffset1 B0 F# Y3 H" c; A' _2 s) v
}6 M0 K8 M# Z' w) }; l
};
% P& g/ S, m4 x* Q$ i+ ~4 Dcoords.bl.corner.tr = {9 u* P. F, S; z
x: coords.bl.corner.br.x + sinoffset,' V' |6 }- H( R: y' [: g: @
y: coords.bl.corner.br.y - cosoffset& R* r8 S* i. I9 z; @2 z# v
};& a4 k+ U v& d2 Z- e1 B& ^
coords.br.corner = {
5 {4 i. _, g* u( O8 D6 t0 ltr: {
7 w1 A) p- M9 S3 P3 E6 Kx: coords.br.x + sinoffset,( @. I9 [3 J& S$ q: R
y: coords.br.y - cosoffset! n$ ~" T, B7 @
},
8 G3 h& g/ H3 x* [' c: Q. Cbl: {" i! e+ }' z- h8 Q
x: coords.br.x - cosoffset,
2 N% |; s9 f8 P9 E" _8 fy: coords.br.y - sinoffset# o+ t5 ]& e! N& Q1 m
},
& ^5 O" r. M! Y) [0 {br: {
6 k' S. q( \2 g# t6 Y$ ?x: coords.br.x,
6 p) |, Z# K2 K# Py: coords.br.y5 w& A$ ?; p3 k# w! I3 c; X
}
5 q0 L2 B/ x0 y7 _/ e, |};( e, Q% l" s: J% a- w& {9 f' X
coords.br.corner.tl = {
3 `. s1 }9 C0 p, T9 qx: coords.br.corner.bl.x + sinoffset,
$ c( S* d5 k9 |y: coords.br.corner.bl.y - cosoffset! ^( Y9 h& H4 f" Z& X0 D; n; W
};
+ X1 @ s" b% R' r};; T- _9 ^7 k( b; x+ V% A
}()); ?3 ]1 O% [7 O4 B8 Y
return canvas;
' Y- a1 f& n U; j0 b% |});0 k" Z8 U' Y! f
puzzle.html代码如下:5 x9 r% p% j) Z" {, ^
复制代码代码如下:<!doctype html>. ^& y$ d( z% g- J
<html>
$ C7 S* f5 K# l# C6 o5 G<head>
/ G9 n4 o' V" X$ U2 I<meta http-equiv=content-type content=text/html; charset=utf-8>, z' P Z0 B% X, F6 I& S5 `
<title>insert title here</title>
! D4 p+ D8 y' ^! ]/ H; K<link type=text/css href=html5_puzzle.css rel=stylesheet />& v9 Q9 G$ n! p2 i, t1 s$ C
<script type=text/javascript src=../multi_upload/seed.js></script>
" @0 h) K2 X" k" x" I<script type=text/javascript src='html5_puzzle.js'></script>
# e4 A$ y7 d( A</head>" Q" h# V, h& ~9 _6 @+ z6 d
<body>
/ I& K+ T n% D7 O5 b7 p6 e<div id='html5_puzzle'>
. E6 n7 j4 V7 G! ~<div id='puzzle_left'>) {: i1 o( Y* I. r' a0 i; y0 ?
<div class='puzzle_column'>/ p# i1 r h6 U+ G
<ul>7 M/ ?( q# H$ W. m8 y
<li><img src='small_img/1.jpg' data-index='1' /></li>
- G4 ~" y* p9 d- M+ [3 u<li><img src='small_img/2.jpg' data-index='2' /></li>& p R& V* ]4 G- w
<li><img src='small_img/3.jpg' data-index='3' /></li>
$ J; }0 A3 N w<li><img src='small_img/4.jpg' data-index='4' /></li>
) l, R- [. L2 U- d! f+ J6 l: D" }<li><img src='small_img/5.jpg' data-index='5' /></li>
/ D' I3 ^$ t2 g! x$ M H</ul>3 l& n4 v8 H0 Q
</div>: b+ @' R' b( U: C7 I
<div class='puzzle_column'>
9 r' A5 m. W: l" I5 T<ul>% `1 W f ^% K* d9 G. A( T8 W
<li><img src='small_img/6.jpg' data-index='6' /></li>
6 \3 n9 q& ~& N, i r b Z<li><img src='small_img/7.jpg' data-index='7' /></li>
0 j/ B9 e6 ~" E* w/ t1 ?% ?$ O<li><img src='small_img/8.jpg' data-index='8' /></li>
" L' T( Y# q4 `6 [<li><img src='small_img/9.jpg' data-index='9' /></li>
! o4 A& A5 T0 r- n& j, e g<li><img src='small_img/10.jpg' data-index='10' /></li>
& L( u. _# u, B" Y" Y7 T7 J9 D</ul>
3 A P. ]8 T) b8 e</div>4 ~& b" p/ U- r7 i, D9 E
</div>2 R# k% v% A, f) g
<div id='puzzle_right'>
" n/ v; f, I; q- x+ X' d0 b<div id='puzzle_canvas'>
' p# R# @& g' J' ]4 C& p<canvas id=canvid1></canvas>" W5 a7 g4 `+ ^; b
<div id='canvas_menu'>3 p' n9 b' l# v% H F
<a href='javascript:void(0)' id='photo_delete'>删除</a> <a
' ]4 P/ e7 m' j: ]% V; Mhref='javascript:void(0)' id='photo_update'>更改图片</a>7 R* U; s2 \; K& [" \: N$ k. g. c& l
</div>
5 c! |3 M) | c2 z( }</div>$ w7 ]/ v- a# T% V3 f* g
<img id=bg src=big_img/1.jpg width='600' height='450' />
/ F: ]8 E# y3 D7 ?</div>9 J+ ^, ?4 j" k) V) J- U
<div id='puzzle_bottom'>
" F& H( s. [! G! Q8 D* r/ X' c<a href='javascript:void(0)' id='add_img'><span>添加图片</span><input
8 W$ ^& u) r6 d/ O6 c4 Ztype=file multiple= id='fileimage'> </a> <a
& I) U' T, ~. |href='javascript:void(0)' id='upload_btn'>上传</a> <a>点击图片可以旋转,拖拽,
! ~4 S: S" S3 B缩放哦!</a> g- ^% z( S E2 p) s
</div>" n$ n' B$ D& n
</div> v% V6 A3 z* B3 `- O
<input type=file id='test'>
3 {4 [) @$ H1 A/ C8 O( _: d7 m<canvas id='test_canvas'></canvas>
) t; h. S; ^2 Z7 ^</body>
. {- l& r: N+ C5 S' Y1 y</html>
; y3 }2 l3 @: V! w# J8 jhtml5_puzzle.css代码如下:+ v9 p4 K) d! ~6 C! _0 a
复制代码代码如下:@charset utf-8;</p> <p>#html5_puzzle {
( Z/ b% C2 T6 {7 l2 w& m0 \; Z, _font-size: 0;
' a8 G. ~$ \* f7 `/ \- l7 x}</p> <p>canvas {
# x' G( u8 ]2 ^& s" z1 j9 ^$ Ebackground-color: transparent;; l5 w- q" S m6 ~8 f+ [$ Q/ {
left: 0;$ O; ~2 [( L( j" B2 |6 l
position: absolute;
! X% D7 h2 k6 B9 H# A) btop: 0;
. d* P9 v1 R- h( m- h$ r}</p> <p>.puzzle_column,#puzzle_left,#puzzle_right,#add_img {
2 V/ Y5 ]" {: C# U4 j% L) }5 edisplay: inline-block;
* Y3 S4 ~$ V* B+ `}</p> <p>.puzzle_column li {. W; D a" Z0 Y4 i q8 w' h6 W2 ?
display: block;
2 C* \0 j1 n% A/ G0 Gmargin: 5px;6 C2 F8 M. W: Y
border: 1px solid #ffffff;6 k8 D3 \! _, t+ G4 W7 K0 b
}</p> <p>.puzzle_column li:hover {
: s5 s# u1 _0 w$ x( t0 ?7 Vborder: 1px solid #3b5998;! V8 X4 j" k/ A2 e
cursor: pointer;7 L/ \) s, J' U4 i' Y8 ?" Q" S. {
}</p> <p>.puzzle_column {
, E2 A' a1 X/ V1 ?font-size: 0;4 ?) E2 q) U$ g8 _1 a; _8 }' o
}</p> <p>#puzzle_left,#puzzle_right {3 I4 m$ X& C& K" f, }
border: 1px solid #3b5998;. E$ w% C+ n; g: h
}</p> <p>#puzzle_right,#puzzle_bottom a {
; z- E" n, P. z h# C8 Zfont-size: 14px;& H1 r& I+ z& W. M& K! ?- R- u- u
margin: 10px 0 0 10px;
5 V1 @1 I! J% s}</p> <p>#puzzle_bottom {0 ]+ q, B1 s# _- j4 e7 D# G
margin: 5px 0;2 U# c' c9 n! f# N6 p, P4 e
}</p> <p>#puzzle_canvas img {; q4 x& H4 Z" w% }8 |( s. z
}</p> <p>#puzzle_canvas {
( g9 ^' a- D8 G: ^2 _8 ooverflow: hidden;
) G( P( [* `/ u7 A) |$ Kwidth: 600px;
8 r3 y# @8 K. J8 [) E4 Mheight: 450px;
& v8 z( g$ M9 b" Fposition: relative;, d' N/ i. \4 y+ z
}</p> <p>#add_img input {
* K2 Q+ \2 t; z( j" e6 rposition: absolute;7 ]6 n- n4 k' ?# W4 G
font-size: 100px;
q( `2 [3 _" B9 xright: 0;. d! u$ h0 P9 m- d8 }+ C
top: 0;
0 ~4 P2 v$ G0 A! Jopacity: 0;( _, P% P- \6 r7 r
}</p> <p>#add_img {
; d% z" j" W4 }- b- ^position: relative;
- x- U& Y C: L! }0 ]+ Fdisplay: inline-block;
" u1 J" @$ B) Z" fbackground: #3b5998;
& }6 ~1 R. R% R/ u8 N, hborder-radius: 4px;
# l9 I' @( E, w* A( Spadding: 4px 12px;
) Z; m+ b/ m( e$ c8 m/ W$ \overflow: hidden;4 Z$ j! J% k4 U7 _4 q2 e6 O
color: #ffffff;
3 r, U' w- {( P$ ~/ j}</p> <p>#bg,#show_list {- }9 q* m, p3 m! H0 j- A5 N4 S( s: A W
display: none; u/ ~9 K- N) ~
}</p> <p>#canvas_menu {
% Z+ p2 J. {- w5 ^$ M0 f1 lborder: 1px solid red; x% z4 U# N; t8 u' ^+ I/ z4 q
position: absolute;5 O5 J* A! i& Y3 O; F& B" A5 v
z-index: 5;" c: [8 g% x* _3 O4 ]% g$ z Z7 W
top: 0;
0 l" ?* Y6 o1 Tleft: 0;
6 G' ]2 }4 V p6 S" N0 D3 F/ Udisplay: none;8 W! G& Y3 v w2 O0 s
}</p> <p>#canvas_menu a {7 h3 ?, V; Q6 I% I& V7 C. I" o
display: inline-block;
! d1 Q, d! A5 A! W}</p> <p>#test_canvas {0 R# V+ @) z6 m+ H, b8 o
top: 700px;
) Y+ ]$ u8 X# z}% B" Y5 Z8 U! ^
html5_puzzle.js代码如下:
4 ^4 q. m/ \. @# M. m" K复制代码代码如下:require([ 'img_upload', '../puzzle/canvasimg', '../puzzle/canvaselement' ], function(
, A4 x" P6 a' zs, canvasimg, canvaselement) {
+ e- P6 w# |) F' d' G: Yvar img=[];8 x! e! J0 C3 J2 `: \
var canvas = new canvaselement.element();. o' `( } \0 `
canvas.init('canvid1', {
0 L& a5 _; c* ]width : 600,- a. i, @; X- M9 W3 [& o
height : 450- z& F& i4 Q. y1 |3 F
});9 p! q* \9 P, a0 g! t/ U2 h
s('.puzzle_column img').on('click',function(e){. l6 X1 ` Q$ Z. G9 H$ y
var index=this.getattribute('data-index');/ ~3 Z* M. H" l
$('bg').onload = function() {' ^3 _7 t% n: ~5 d9 H. u
var ctx=$('canvid1-canvas-background').getcontext('2d');0 h7 T4 _; k3 }! A* H
ctx.clearrect(0, 0,600,450);4 z2 M' P, H3 G( j: h! g6 s# f
img[0]=new canvasimg.img($('bg'), {});
( C8 L; {8 v4 |- [canvas.setcanvasbackground(img[0]);
0 i' x1 B% y+ D0 U3 e5 G" @- ^5 U};
2 ?: q( v: a% `% @" N$('bg').setattribute('src','medium_img/'+index+'.jpg');
5 C9 D0 T$ S0 K6 J- j" `e.stoppropagation();& u1 H2 A2 ^/ E8 i
});
. Z" K0 Q$ h$ ?0 n: H8 X9 xvar canvasdemo = function() {
. B- g+ P/ |8 [! `9 l; Areturn {& r! z, ]8 K% d+ u" F# k8 [
init : function() {6 W0 X5 O+ y, e" Q7 t
var img_list=dom.query('#puzzle_canvas img');
" s) |, o- S8 Y, F8 J8 z+ B9 Gimg[0]=new canvasimg.img($('bg'), {});+ b7 g' y, |0 w' g
s.each(img_list,function(i,el){
, f2 X# s6 O( c2 h) g' N1 Bel.setattribute('data-index',i);
: M+ ^& g7 [+ X/ vimg.push(new canvasimg.img(el, {}));
" S' O2 `8 V3 e8 s" fcanvas.addimage(img[i+1]);
: ?" ?9 s' w5 l$ f8 m% ?9 d});
8 [) \" ~: ~3 k8 E4 Y9 Q* ycanvas.setcanvasbackground(img[0]);9 f- [8 ^6 E. K# O: q
this.cornersvisible = (this.cornersvisible) ? false : true;
3 h6 A" x0 u4 j6 I. P; O6 Dthis.modifyimages(function(image) {
& z9 r c. H- Gimage.setcornersvisibility(this.cornersvisible);5 U1 i% d$ y6 d$ n* a8 }
});
# T4 p: u, W6 T( ]* }8 W},
% Y! ?2 ?2 \; Y. h3 jmodifyimages : function(fn) {
8 e1 y4 ~1 D: {$ s. T% E/ Hfor ( var i =0, l = canvas._aimages.length; i < l; i += 1) {* n. M3 l2 b5 x3 J d2 I' f5 @7 q
fn.call(this, canvas._aimages);
4 ~- c" U5 J* i* ?* L}, F) x* Y6 p. K) ]" O
canvas.renderall(false,false);; x8 B) H3 W, k4 r
s('#puzzle_canvas img').remove();
4 `( }* r. x' O+ w3 Nimg = [];6 g$ i9 F% j* Z* d( C% }# }
}3 Y& t' d: X4 V' O( [6 D: s$ U
};8 M7 E, O( B9 E- x) \
}();: w& A- X# O) s* C
function getcurimg(){: v% |6 }3 C5 @! F/ r% K F X
var oimg=canvas._prevtransform.target;/ l6 M9 `. s1 W8 k) ]* J
for(var i=0;i<canvas._aimages.length;i++){2 R9 J6 g$ Z) k) t8 t4 }
if(canvas._aimages._oelement.src==oimg._oelement.src){
6 s! D+ A! N6 f4 Nreturn i;' T. U6 P9 u* B& [8 b
}
6 t$ C1 s. T2 v. h1 c}/ x$ ~% S5 J. K' S, ~7 w
}
& N* h6 s9 Z4 Z4 `7 l7 Ts('#photo_delete').on('click',function(e){0 d4 \% H% E# [" x
var i=getcurimg();( ]7 M5 _, f0 L
canvas._aimages.splice(i,1);1 @; _2 M& ?$ l! Q+ B( ~9 | O4 E" G
canvas.renderall(true,true);9 [7 ^& W8 Y- J' W3 k0 C
$('canvas_menu').style.display=none;
5 o1 u2 @1 d" @# w});
& O& e$ h. R* D8 G5 @) os('#photo_update').on('click',function(e){
/ c3 L1 ~$ k) i5 B. p$('test').click();% p' o8 o9 p' h8 v% ^5 u
});
* T' V1 j4 g" a J# As('#test').on('change',function(e){
& m5 t) S+ N) @& }var files = e.target.files || e.datatransfer.files;
0 Z6 x$ X5 h# I" H1 {' ~ p$ uvar reader = new filereader();$ T# X! W3 ~3 W+ j: L2 G7 A& L
reader.onload = (function() {
1 v2 t3 W5 y; T4 Qreturn function(e) {2 v/ S i( v# y4 g* {9 n, r
var dataurl = e.target.result, canvas1 = document.queryselector('#test_canvas'), ctx = canvas1.getcontext('2d'), img = new image();2 C* V i) F2 [& }/ }+ |
img.onload = function(e) {
# L8 A; B) j/ [ ^3 J# aif(img.width>200||img.height>200){3 m8 u7 R W) a. Q
var prop=math.min(200/img.width,200/img.height);
. @2 P: M$ o4 R2 B7 T% G/ Rimg.width=img.width*prop;
0 Z- n9 u U! `8 t9 q! e" T, Gimg.height=img.height*prop;: B) D7 L! J0 K# N
}
y8 l, q" k, G- @# O# Z4 O. |canvas1.width=img.width;
. _- y4 w4 j3 s& N; d8 F1 ^0 pcanvas1.height=img.height;
- o- N$ ?* R) T$ ictx.drawimage(img, 0, 0, img.width, img.height);
! |: b6 A& J) U3 e4 f; Ss('#canvid1').html(s('#canvid1').html()+<img src='+canvas1.todataurl(image/jpeg)+'/>);
1 _: \9 }! k) A; o6 U6 s% k i- dvar t = window.settimeout(function() {
9 H. S1 ?, ]) _+ h- L" Fvar i=getcurimg(),target=canvas._prevtransform.target; ~8 C+ h. Q6 d3 u
console.log(target);5 Z4 a1 S; s. g2 O! G- i! I
canvas._aimages=new canvasimg.img(dom.query('#canvid1 img')[0], {
/ n0 F# v% a! ^5 L: @/ n2 ~top:target.top,6 u* B2 w% K" Y, v
left:target.left,, Y& `& P! X( `' E$ t( |- d q/ m: C
scalex:target.scalex,+ r5 R) d- p. I7 O% p+ _5 x4 p
scaley:target.scaley,
7 n2 N' \1 V+ cangle:canvas.curangle
8 { a3 ~! j, |; Q1 ?});
% ?8 b& l1 d; O# M! f$ \canvas.rendertop();
1 J7 J6 A# P4 w7 o' L; h A3 Zcleartimeout(t);0 O3 j! S3 ?' ^& ~5 `( T2 ~! g' i
s('#canvid1 img').remove();
3 S8 t2 Y# N( \3 c9 u8 o; k; v},1000);. m9 \) Z5 ^! E& j# a
};0 j) e. C; p1 L- B; S; S
img.src = dataurl;
" g& f5 `& k! R/ {7 ]! D};- p1 q. q- @7 L1 W. s- ^# K
})();
4 _7 j* a [) Y" j5 Oreader.readasdataurl(files[0]);
; l: d6 Y- T) v- e% I8 O});' i. h( O/ c8 t) A; M) L
s('#upload_btn').on('click',function(){
) l9 f H' z% y W+ e; Y& Xvar imgdata = canvas.canvasto('jpeg');
& Z0 h# a! q$ D2 v" v7 o# o( @var imgvalue = imgdata.substr(22);0 r+ C* O( Y3 S" r2 U
s.ajax({5 O/ p, h5 v6 z+ p' B* v& h" p
url : 'http://localhost/html5/upload1.php'," \1 u+ g. U! Q
type : 'post',, E5 o3 I% M" x6 R
data : {
+ d2 ~/ W+ U: c+ timgdata : imgvalue,
3 i4 _8 o4 _0 }" c' S0 C) t8 Zfile_name :'mix_img.jpeg'
+ c8 C$ @$ o2 B% _% N},1 p* P" w) M" v3 i, v
datatype : 'text',
8 S; m: e9 l1 U9 ~# |9 L) Q8 b) bsuccess : function(data) {" v5 o6 e: b' j0 w! E* L: Y
alert(s);# G+ @' d% J: o; V0 R8 B ^. S/ ?" v" R
}
# H* i8 z- p3 @});0 H6 Q: ?2 d! b! R
});; N5 c# l, w" b- n8 ]
});2 |& r- a( I5 t: L; @+ ?7 I$ _
至于用html5 input读取图片,这很简单就不贴出来了。) |) J, n1 z" m' _' ~4 _ o, n
l( E' Y J/ D0 X+ B
更多网页制作信息请查看: 网页制作 |