I'm making a chatroom-like website using vue.
I use display: flex & column-reverse on css to reverse messages view.
And use Array unshift to insert new message.
On chrome & firefox, this will always keep the newest message(at bottom) in view.
But safari don't.
I tried method "scrollTo" after new message append, but it seems not working without user interact.
(New message may append without any user interact in a short time before)
I also tried detect whether bottom or not using "scrollTop" (then I can notice user a new message came in) but failed on safari too.
Any other way to make safari work the same as chrome/firefox do?
A demo here, can open with safari with the problem.
<!-- Use preprocessors via the lang attribute! e.g. <template lang="pug"> -->
<template>
<div id="app" ref="app">
<p
v-for="message in messages"
>
{{ message }}
</p>
</div>
</template>
<script>
export default {
data() {
return {
messages: []
};
},
mounted() {
setInterval(() => {
this.messages.unshift((new Date()).toString())
this.$nextTick(() => {
this.$refs.app.scrollTo(0, 0)
})
}, 1000)
}
};
</script>
<!-- Use preprocessors via the lang attribute! e.g. <style lang="scss"> -->
<style>
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
text-align: center;
color: #2c3e50;
display: flex;
flex-direction: column-reverse;
overflow-y: scroll;
scroll-behavior: smooth;
height: 90vh;
}
a,
button {
color: #4fc08d;
}
button {
background: none;
border: solid 1px;
border-radius: 2em;
font: inherit;
padding: 0.75em 2em;
}
</style>
Changing your overflow
from scroll
to visible
should solve this issue.
#app {
overflow: visible;
}
The reason why it's not scrolling is your #app
container does not pick up the content height changed inside the app box,