xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

auto scroll bottom in js

auto scroll bottom in js


    autoScrollToBottom() {
        let box = document.querySelector(`[data-dom="chatroom-content"]`);
        let height = box.scrollHeight;
        box.scrollTo(0, height);
    },

demo

refs

https://developer.mozilla.org/en-US/docs/Web/API/Window/scroll

https://mdn.github.io/dom-examples/scrolltooptions/
https://github.com/mdn/dom-examples/tree/master/scrolltooptions


window.scroll(x-coord, y-coord)
window.scroll(options)

https://developer.mozilla.org/en-US/docs/Web/API/ScrollToOptions



https://developer.mozilla.org/en-US/docs/Web/API/Window/scrollTo


window.scrollTo(x-coord, y-coord)
window.scrollTo(options)





https://www.cnblogs.com/xgqfrms/p/9416358.html

https://www.cnblogs.com/xgqfrms/p/9707267.html

window.requestAnimationFrame

https://developer.mozilla.org/en-US/docs/Web/API/Window/requestAnimationFrame


      // setTimeout(() => {
      //   this.goToTop.current.style.display = "none";
      // }, 1000);
      let timestamp = 1000;
      function step() {
        timestamp --;
        if (timestamp > 0) {
          window.requestAnimationFrame(step);
        } else {
          this.goToTop.current.style.display = "none";
        }
      }
      window.requestAnimationFrame(step);

refs



©xgqfrms 2012-2020

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!


posted @ 2019-07-02 10:34  xgqfrms  阅读(124)  评论(5编辑  收藏  举报