Skip to content Skip to sidebar Skip to footer

Javascript: Scrollby Function Executed On A Div

I have a div with overflow: scroll; And I would like to put a button. When you press it, the content of the div scrolls. Something like: This works in FF, but not in Chrome. In C

Solution 1:

You can try this:

functionscrollDiv(){
    document.getElementById("d").scrollTop += 100;
    document.getElementById("d").scrollLeft += 100;
}

Solution 2:

Rather than do

functionscrollDiv(){
   document.getElementById("d").scrollTop += 100;
   document.getElementById("d").scrollLeft += 100;
}

would you not do

document.getElementById("d").scrollBy({
   top: 100,
   left: 100,
   behaviour: 'smooth'
})

Post a Comment for "Javascript: Scrollby Function Executed On A Div"