How to have a textarea to keep scrolled to the bottom when updated

前端 未结 5 1920
礼貌的吻别
礼貌的吻别 2020-12-03 03:06

My problem is a bit off the cuff here, so I\'ll try to explain this best I can.

I have a text area, having css of #object{overflow:hidden;resize:none;}.

5条回答
  •  遥遥无期
    2020-12-03 03:39

    function checkTextareaHeight(){
       var textarea = document.getElementById("yourTextArea");
       if(textarea.selectionStart == textarea.selectionEnd) {
          textarea.scrollTop = textarea.scrollHeight;
       }
    }
    

    Call this function every time when the contents of the textarea are changed. If you cannot edit the external influence, periodically activate this function using setInterval.

提交回复
热议问题