-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUndoRedo.js
More file actions
40 lines (31 loc) · 830 Bytes
/
UndoRedo.js
File metadata and controls
40 lines (31 loc) · 830 Bytes
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
var newList = [];
var step = 0;
function saveHistory() {
step++;
lastStep = canvasReal.toDataURL();
newList.push(lastStep);
}
$("#undo").click(function () {
if (step > 0) {
step--;
let lastURL = newList[step - 1];
let img = document.createElement('img');
img.src = lastURL;
img.onload = () => {
contextReal.clearRect(0, 0, canvasReal.width, canvasReal.height);
contextReal.drawImage(img, 0, 0);
}
}
})
$("#redo").click(function () {
if (newList.length > step) {
step++;
let lastURL = newList[step - 1];
let img = document.createElement('img');
img.src = lastURL;
img.onload = () => {
contextReal.clearRect(0, 0, canvasReal.width, canvasReal.height);
contextReal.drawImage(img, 0, 0);
}
}
})