문제

I would like to force a scroll in javascript so i wrote that script but it doesn't work. The script makes the user scroll and after his execution, it goes back to the top of the page.

function myscroll(i)
{
    if (document.body.scrollTop < i - 100)
    {
        document.body.scrollTop += 10;
        setTimeout(myscroll(i), 10);
    }
}

How can i fix that ?

Thanks for reading.

도움이 되었습니까?

해결책

You need to use an anonymous function for setTimeout to work as you'd expect:

setTimeout(function() {
    myscroll(i)
}, 10);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top