页面或元素内容滚动到底部

 

inputFocus(){
      //监听输入框获得焦点,判断软键盘弹起
      let bodyEle = document.documentElement || document.body;
      this.$nextTick(()=>{
        bodyEle.scrollTop = bodyEle.scrollHeight;
        setTimeout(()=>{//这个计时器是等待dom刷新后 定位完成
          this.$refs.mchat.scrollTop = this.$refs.mchat.scrollHeight;
        },500);
      });
    },

 

 精确适配

inputFocus(){
      //监听输入框获得焦点,判断软键盘弹起
      this.$nextTick(()=>{
        setTimeout(()=>{
          this.$refs.mchat.scrollTop = this.$refs.mchat.scrollHeight;
            if( this.windowInitHeight == 460 ){//适配iphone4
              document.body.scrollTop = this.windowInitHeight - window.innerHeight - 10;
            }else{
              document.body.scrollTop = this.windowInitHeight - window.innerHeight;
            }
            if(document.body.scrollTop < 1){//若document.body.scrollTop 设置后没生效  则设置document.documentElement.scrollTop
              document.documentElement.scrollTop = this.windowInitHeight - window.innerHeight;
            }
        },500)
      });
    },

mounted中 给this.windowInitHeigh 赋值为window.innerHeight

 

posted @ 2020-08-26 18:32  古墩古墩  Views(662)  Comments(0Edit  收藏  举报