forked from tybro0103/jWindowCrop
-
Notifications
You must be signed in to change notification settings - Fork 13
/
index.html
95 lines (93 loc) · 2.76 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<!DOCTYPE html>
<html>
<head>
<title>jQuery-crop</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1"/>
<link type="text/css" media="screen" rel="stylesheet" href="jquery.crop.css">
<style type="text/css">
body {
font-family : sans-serif;
font-size : 13px;
}
.results {
font-family : monospace;
font-size : 20px;
}
.cropFrame {
border : 4px solid black;
}
</style>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0-alpha1/jquery.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/hammer.js/2.0.4/hammer.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery-mousewheel/3.1.13/jquery.mousewheel.min.js"></script>
<script type="text/javascript" src="jquery.crop.js"></script>
<script type="text/javascript">
$( function () {
$( '.crop' ).each( function () {
var image = $( this )
, results = image.next( '.results' )
, x = $( '.cropX', results )
, y = $( '.cropY', results )
, w = $( '.cropW', results )
, h = $( '.cropH', results )
, crop = image
.crop( {
controls : 'Drag to move, scroll to zoom'
} )
// display crop info
.on( 'crop.crop', function( event ) {
x.text( event.cropX );
y.text( event.cropY );
w.text( event.cropW );
h.text( event.cropH );
} )
.data( 'crop' )
;
// zoom on scroll (jquery-mousewheel dependency)
image
.on( 'mousewheel.crop', function ( event ) {
return event.originalEvent.wheelDelta < 0 ?
crop.zoomIn() :
crop.zoomOut();
} )
;
// zoom on pinch touch (hammer dependency)
Hammer( this )
.on( 'pinchin', function ( event ) {
return crop.zoomOut();
} )
.on( 'pinchout', function ( event ) {
return crop.zoomIn();
} )
.on( 'drag', function ( event ) {
crop.$image
.css( {
left : '+=' + event.deltaX
, top : '+=' + event.deltaY
} )
;
crop.update();
} )
;
} );
} );
</script>
</head>
<body>
<img class="crop" alt="" src="dock.jpg" width="400" height="300" />
<div class="results">
<b>X</b>: <span class="cropX"></span>
<b>Y</b>: <span class="cropY"></span>
<b>W</b>: <span class="cropW"></span>
<b>H</b>: <span class="cropH"></span>
</div>
<img class="crop" alt="" src="beach.jpg" width="300" height="200" />
<div class="results">
<b>X</b>: <span class="cropX"></span>
<b>Y</b>: <span class="cropY"></span>
<b>W</b>: <span class="cropW"></span>
<b>H</b>: <span class="cropH"></span>
</div>
</body>
</html>