create a div that scrolls horizontally and adjust its height to always be 80% of the screen height in javascript

<div id="scrollingDiv"></div>
30 chars
2 lines
#scrollingDiv {
   height: 80vh; /* set height to 80% of viewport height */
   display: flex;
   flex-wrap: nowrap; /* Make sure the div doesn't wrap */
   overflow-x: auto; /* Allow horizontal scrolling */
}
209 chars
7 lines
index.tsx
// Use DOM manipulation to add content to the scrolling div
const scrollingDiv = document.getElementById('scrollingDiv');

for (let i = 0; i < 20; i++) {
    const div = document.createElement('div');
    div.textContent = i;
    scrollingDiv.appendChild(div);
}
263 chars
9 lines

This code creates a div with the id "scrollingDiv" and sets its height to 80% of the viewport height. It uses CSS flexbox to make sure the contents of the div don't wrap and allows horizontal scrolling with the overflow-x property set to "auto".

The JavaScript code then uses DOM manipulation to add content to the scrolling div. A loop is used to create 20 child divs with incrementing text content, which are then appended to the scrolling div.

gistlibby LogSnag