<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Do Code : Infinite Scroller Using Js And Css</title>
</head>
<style>
    *,
    *::before,
    *::after {
        box-sizing: border-box;
        padding: 0;
        margin: 0;
    }

    html,
    body {
        width: 100%;
        height: 100%;
    }

    body {
        background-color: #dadada;
    }

    body>h1 {
        text-align: center;
        margin: 1rem auto;
        text-transform: capitalize;
    }

    .scrollContainer {
        max-width: 1200px;
        margin: 0 auto;
        /* border: 1px solid red; */
        overflow-x: hidden;
        -webkit-mask: linear-gradient(90deg, transparent, white 20%, white 80%, transparent);
    }

    /* stop animation on hover */
    .scrollContainer:hover .scrollWrapper {
        animation-play-state: paused;
    }

    .scrollContainer .scrollWrapper {
        display: flex;
        gap: 1rem;
        animation: scrollAnim 15s infinite linear;
        width: max-content;
    }

    .scrollContainer .scrollWrapper .item {
        width: 200px;
        height: 200px;
        background-color: aquamarine;
        font-size: clamp(2rem, 4vw, 4rem);
        display: flex;
        justify-content: center;
        align-items: center;
        flex-shrink: 0;
        transition: 200ms ease-in-out;
    }
    .scrollContainer .scrollWrapper .item:hover{
        background-color: rgb(110, 236, 194);
        cursor: pointer;
    }

    /* way 1 :-  to fix this glitch */
    /* .scrollContainer .scrollWrapper .item:nth-child(1){
        margin-left: 1rem;
    } */

    /* animation */
    @keyframes scrollAnim {

        /* to {
            transform: translateX(-50%);
        } */
        /* second way to fix glitch */
        to {
            transform: translateX(calc(-50% - 0.5rem));
        }
    }

    /* check flag */
    /* .red {
        background-color: red !important;
    } */
</style>

<body>
    <h1>Infinite Scroller Using Js And Css</h1>
    <div class="scrollContainer">
        <div class="scrollWrapper">
            <div class="item">1</div>
            <div class="item">2</div>
            <div class="item">3</div>
            <div class="item">4</div>
            <div class="item">5</div>
            <div class="item">6</div>
        </div>
    </div>
    <script>
        const scrollWrapper = document.querySelector('.scrollWrapper');
        const items = [...scrollWrapper.children];

        items.forEach((item) => {
            const clonedItem = item.cloneNode(true);
            // clonedItem.classList.add("red");
            scrollWrapper.appendChild(clonedItem);
        })
    </script>
</body>

</html>
/* No CSS found */
// No JS found