1

I am using pure javascript for vertical scroll.I need this scroll to have smooth behaviour.

function move_up(scroll_nav)
    {
        var container = document.getElementById(scroll_nav);
        upScroll(container,'up',40,50,10);

    }

    function move_down(scroll_nav)
    {
        var container = document.getElementById(scroll_nav);
        upScroll(container,'down',40,50,10);

    }

    function upScroll(element,direction,speed,distance,step)
    {
        scrollAmount = 0;
        var slideTimer = setInterval(function(){
            if(direction == 'up'){
                element.scrollTop  -= step;
            } else {
                element.scrollTop  += step;
            }
            scrollAmount += step;
            if(scrollAmount >= distance){
                window.clearInterval(slideTimer);
            }
        }, speed);
    }

I need an animate function similar to the one in this link but without jquery. https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_smooth_scroll_jquery

I need an animate function to be included Please provide an solution .

1 Answer 1

4

element.scrollTo({ top: ..., behavior: 'smooth' });

Sign up to request clarification or add additional context in comments.

2 Comments

No I want to have smooth animate effect.Thanks for your code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.