JSFiddle - React, Tailwind, and code Playground
HTML
<head>
<script src='https://html2canvas.hertzen.com/dist/html2canvas.min.js'></script>
</head>
<body style="min-height: 100vh; overflow-y: hidden; width: 100%; max-width: 100%; overflow-x: none; background-color: white;">
<!-- Top Navbar -->
<nav class="navbar navbar-expand-md" style="background-color: black; height: 80px;">
<button onclick="grab()" style="font-size: 18pt; width: 150px; height: 40px; right: 100px;">Download</button>
</nav>
<!-- Main Container -->
<div id ="capture" style="display: flex; height: calc(100vh - 105px); flex-direction: column;">
<div id="top-container" style="width: 100%; flex-grow: 0; display: flex; flex-direction: row;flex-shrink: 0; height: 200px; background-color: lightgray;overflow-y: none; overflow-x: scroll;">
<button onclick="addInfo()" style="font-size: 18pt; flex-shrink: 0; width: 40px; height: 40px; border-radius: 20px; right: 25px;top: 14%;">+</button>
</div>
</div>
</body>
JavaScript
function addInfo() {
document.getElementById("top-container").insertAdjacentHTML('beforeend', `
<div style="flex-grow: 0;">
<textarea class = "info" cols="30" rows="10" style="margin-left: 20px; margin-top: 20px; background-color: white; color: black; border: 2px solid black; width: 100px; height: 100px; resize: none;"></textarea>
</div>
`)
}
function grab() {
const captureElement = document.querySelector('#capture')
html2canvas(captureElement)
.then(canvas => {
canvas.style.display = 'none'
document.body.appendChild(canvas)
return canvas
})
.then(canvas => {
const image = canvas.toDataURL('image/png').replace('image/png', 'image/octet-stream')
const a = document.createElement('a')
a.setAttribute('download', 'my-image.png')
a.setAttribute('href', image)
a.click()
canvas.remove()
})
capture.style.oveflow = 'scroll'
}