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
;-)
Written by Valentin Beuret
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Javascript
Authors
Related Tags
#javascript
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#