Saving scroll momentum for touch interface devices when using scrollTo

I am currently writing a website where, when you reach a certain position, you are thrown up to an identical position without any animation. Because of this, it should feel like you’re endlessly scrolling. I used the window.scrollTo function to implement this. At the same time, it works perfectly on a computer and laptop. However, when used on a phone, the scroll speed is reset when moving up. How can this be fixed?

You need to at least understand the cause of the problem, and at best immediately find out its direct solution.

This is example of code

HTML

<section class="galery">
    <section class="column1">
        <section class="item" id="101">
            <img class="galery_item" alt="Picture">
        </section>
        <section class="item" id="102">
            <img class="galery_item" alt="Picture">
        </section>
        <section class="item" id="103">
            <img class="galery_item" alt="Picture">
        </section>
        <section class="item" id="104">
            <img class="galery_item" alt="Picture">
        </section>
        <section class="item" id="105">
            <img class="galery_item" alt="Picture">
        </section>
        <section class="item" id="106">
            <img class="galery_item" alt="Picture">
        </section>
        <section class="item" id="107">
            <img class="galery_item" alt="Picture">
        </section>
    </section>
    ***Other column***
</section>

JS

if('ontouchstart' in window || navigator.maxTouchPoints){
    window.addEventListener('touchend', () =>{
        flag = true;
    });
    window.addEventListener('touchstart', () =>{
        flag = false;
    });
    window.addEventListener('scroll', () =>{
        if(flag){
            if(***coordinates of the lower boundary*** <= pageYOffset){
                window.scrollTo(0, ***coordinates of the indented upper boundary***);
            }
            else if(***coordinates of the upper boundary*** >= pageYOffset){
                window.scrollTo(0,  ***coordinates of the indented lower boundary***);
            }
        }
    });
}

this is what the site looks like

enter image description here

when the user reaches a certain lower limit, he is thrown up to the same picture. The result is a visual effect of endless scrolling. But on devices with touch interface, the scrolling pulse is not saved when the scrollTo function is triggered and the screen stops abruptly. This needs to be fixed.

There have been attempts to make the main event trigger a function like touchend rather than scroll, but this has led to the user reaching the bottom of the site too quickly and having to greatly increase the html code.