Last Updated: February 25, 2016
·
1.14K
· beuretv

scroll to div (left and right)

You can change the X to Y value tu scroll up and down to div or elements with id.

function scrolltoDiv(id_divto){




//check if div must mouve
if(document.getElementById(id_divto).offsetLeft == window.pageXOffset){

    clearInterval(Divabord);

    }else{

    var Divabord = setInterval(function(){

    var currentPos = window.pageXOffset;

    var destinatPos = document.getElementById(id_divto).offsetLeft;

    var calcPos = parseInt(destinatPos)-(currentPos);

        //vitesse initiale du scroll
    var x = 25;


    //smoot a end


    var xu = 25;

    var xul =  parseInt(currentPos)+(xu);





        //incrementation de la vitesse
        var incrementX;


        // on va a droite
    if(currentPos < destinatPos){

        if(xul > destinatPos){

            x= 1;

        }

            var incrementX = x++;


            positionX =  parseInt(currentPos)+(incrementX);



        }

        //on va a gauche
    if(currentPos > destinatPos){

            if(xul < destinatPos){

                x= 1;

            }

            var incrementX = x++;


            positionX =  parseInt(currentPos)-(incrementX);


        }


    window.scrollBy(positionX,0);

    window.scrollTo(positionX,0);


    if(document.getElementById(id_divto).offsetLeft == window.pageXOffset){

    clearInterval(Divabord);

    }

    },1);

}

}

body overflow must be hidden

;-)