Day # 76: Screenshot
Using canvas along with Javascript allows you to obtain a screenshot. The key here is to select the section of the document that you want to capture:
<button id="capture-btn" title="Get Screenshot!">
<i class="fa-solid fa-camera-retro"></i>
</button>
canvas2html was used in order to capture the elements within the specified container:
captureBtn.addEventListener("click", async() => {
downloadBtn.classList.remove("hide")
const canvas = await html2canvas(container)
const imageURL = canvas.toDataURL()
previewContainer.innerHTML = `<img src="${imageURL}" id="image">`
})
Comments
Post a Comment