-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
67 lines (54 loc) · 2.33 KB
/
script.js
File metadata and controls
67 lines (54 loc) · 2.33 KB
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
$(document).ready(function () {
const form = document.querySelector("#testimoniInput");
form.addEventListener('submit', (event)=>{
let username = form.elements["nama"].value;
let testimoni = form.elements["testimoni"].value;
let inisial = username[0].toUpperCase();
document.getElementById('inisial').innerHTML = inisial;
document.getElementById('uname').innerHTML = inisial + username.slice(1);
document.getElementById('testimoniText').innerHTML = testimoni;
event.preventDefault(); //prevent the form from resseting the entire pages
});
const testimoniText = document.querySelector('#testimoniText');
document.querySelector("#left").addEventListener('click', () => {
testimoniText.style.textAlign = 'left';
});
document.querySelector("#center").addEventListener('click', () => {
testimoniText.style.textAlign = 'center';
});
document.querySelector("#right").addEventListener('click', () => {
testimoniText.style.textAlign = 'right';
});
document.querySelector("#justify").addEventListener('click', () => {
testimoniText.style.textAlign = 'justify';
});
// Global variable
var element = $(".list li");
// Global variable
var getCanvas;
$("#btn-Preview-Image").on('click', function () {
html2canvas(element, {
logging: true,
useCORS: true, // This helps with handling cross-origin images
scale: 2, // You can adjust scaling to manage the output resolution
onrendered: (function (canvas) {
$("#previewImage").empty().append(canvas); // Clear existing canvas before appending new one
getCanvas = canvas;
}),
catch: (function (error) {
console.error('Error during canvas rendering:', error);
})
});
});
$("#btn-Convert-Html2Image").on('click', function () {
var imgageData =
getCanvas.toDataURL("image/png");
// Now browser starts downloading
// it instead of just showing it
var newData = imgageData.replace(
/^data:image\/png/, "data:application/octet-stream");
$("#btn-Convert-Html2Image").attr(
"download", "Testimoni.png").attr(
"href", newData);
});
});