[removed] scrollBy function executed on a div

前端 未结 2 1758
难免孤独
难免孤独 2021-02-13 03:55

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:

2条回答
  •  忘掉有多难
    2021-02-13 04:18

    Rather than do

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

    would you not do

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

提交回复
热议问题