Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QScrollArea, scroll to bottom #6167

Closed
hlb8122 opened this issue Jan 21, 2020 · 2 comments
Closed

QScrollArea, scroll to bottom #6167

hlb8122 opened this issue Jan 21, 2020 · 2 comments

Comments

@hlb8122
Copy link

hlb8122 commented Jan 21, 2020

Is your feature request related to a problem? Please describe.
In some applications, such as a messaging apps chat box, one would like to scroll to the bottom of a QScrollArea on a new message.

Describe the solution you'd like
An API method for QScrollArea to scroll to the bottom.

Describe alternatives you've considered

      this.$refs.chatScroll.setScrollPosition(this.$refs.chatScroll.$el.scrollHeight, 1)

setScrollPosition is such a method but the above doesn't seem to scroll to bottom correctly all the time.

@pdanpdan
Copy link
Collaborator

const scrollArea = this.$refs.chatScroll;
const scrollTarget = scrollArea.getScrollTarget();
const duration = 300; // ms - use 0 to instant scroll
scrollArea.setScrollPosition(scrollTarget.scrollHeight, duration);

https://codepen.io/pdanpdan/pen/yLyQdOz?editors=1010

@ligecarryme
Copy link

ligecarryme commented Oct 26, 2020

<q-scroll-area ref="chatArea" @scroll="scrollinfo" >
      <div v-for="item of message" :key="item.id">
         <q-chat-message :name="item.nickname" :text="[item.content]" :stamp="item.createTime" />
       </div>
    <q-scroll-observer /> <!-- 监控滑动区域,主要监控滑动条的长度。绑定scroll方法 -->
</q-scroll-area>
data(){
    return {
	scrollsize: 0;
    }
},
watch:{ // 监控滚动条的变化
    scrollsize: function(val){
  		this.$refs.chatArea.setScrollPosition(val-500,100); //设置到底部,500是我自己设置的聊天区域高度
	}
},
scrollinfo(info){ 
  const size = info.verticalSize;
  this.scrollsize = size;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants