/
example.html
76 lines (67 loc) · 1.96 KB
/
example.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
<!DOCTYPE html>
<html>
<head>
<title>Cropper Example</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="build/cropper.css">
<style type="text/css">
img {
display: block;
margin: 3em auto;
position: relative;
top: -14px;
}
.cropped {
box-shadow: 0 0 3px rgba(0, 0, 0, .5);
}
.controls {
text-align: center;
}
#crop { display: block; margin: 12px auto; }
</style>
</head>
<body>
<div class="controls">
<label>
Ratio
<select>
<option>None</option>
<option value="square">Square</option>
<option value="3:2">3:2</option>
<option value="4:3">4:3</option>
<option value="5:2">5:2</option>
<option value="5:4">5:4</option>
<option value="6:4">6:4</option>
<option value="7:5">7:5</option>
<option value="10:8">10:8</option>
<option value="16:9">16:9</option>
</select>
<button id="ratio">Apply</button>
</label>
<button id="crop">Crop!</button>
</div>
<img src="grumpy-cat-example.jpg" alt="grumpy"/>
<script src="build/cropper.js"></script>
<script>
window.onload = function () {
var Cropper = require('cropper'),
crop = new Cropper(document.querySelector('img'));
document.getElementById('crop').addEventListener('click', function () {
var img = document.querySelector('img');
img.parentNode.removeChild(img);
img = document.createElement('img');
img.src = crop.get();
img.className = 'cropped';
document.body.appendChild(img);
crop.destroy();
var controls = document.querySelector('.controls');
controls.parentNode.removeChild(controls);
});
document.getElementById('ratio').addEventListener('click', function () {
var select = document.querySelector('select');
crop.setRatio(select.options[select.selectedIndex].value);
});
};
</script>
</body>
</html>