[removed] scrollBy function executed on a div

前端 未结 2 1753
难免孤独
难免孤独 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

    You can try this:

    function scrollDiv(){
        document.getElementById("d").scrollTop += 100;
        document.getElementById("d").scrollLeft += 100;
    }
    
    0 讨论(0)
  • 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'
    })
    
    0 讨论(0)
提交回复
热议问题