-
Notifications
You must be signed in to change notification settings - Fork 9
/
index.js
89 lines (70 loc) · 2.14 KB
/
index.js
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
let camera_button = document.querySelector("#start-camera");
let video = document.querySelector("#video");
let click_button = document.querySelector("#click-photo");
let canvas = document.querySelector("#canvas");
var constraints = {
audio: false,
video: {
facingMode: 'user'
}
}
video.setAttribute('autoplay', '');
video.setAttribute('muted', '');
video.setAttribute('playsinline', '')
function takeshot() {
let div =
document.getElementById('photoframe');
html2canvas(div,{
dpi: 144,
allowTaint: true
}).then(
function (canvas) {
return Canvas2Image.saveAsPNG(canvas);
})
}
camera_button.addEventListener('click', async function() {
let stream = await navigator.mediaDevices.getUserMedia(constraints);
video.srcObject = stream;
});
camera_button.click();
click_button.addEventListener('click', function() {
canvas.getContext('2d').drawImage(video, 0, 0, canvas.width, canvas.height);
let image_data_url = canvas.toDataURL('image/jpeg', 1.0);
//takeshot();
// data url of the image
// console.log(image_data_url);
});
const items = document.querySelectorAll('img');
const itemCount = items.length;
const nextItem = document.querySelector('.next');
const previousItem = document.querySelector('.previous');
let count = 0;
function showNextItem() {
items[count].classList.remove('active');
if(count < itemCount - 1) {
count++;
} else {
count = 0;
}
items[count].classList.add('active');
console.log(count);
}
function showPreviousItem() {
items[count].classList.remove('active');
if(count > 0) {
count--;
} else {
count = itemCount - 1;
}
items[count].classList.add('active');
console.log(count);
}
nextItem.addEventListener('click', showNextItem);
previousItem.addEventListener('click', showPreviousItem);
$(document).ready(function(){
$('.frame').click(function(){
var imagePath = $(this).attr('src');
$('.framebg').css({"background-image": "url(" + imagePath + ")"});
$('.card').css({"background-image": "url(" + imagePath + ")"});
});
});