fix the bug with scrolling post comments into view

This commit is contained in:
Vasily Belolapotkov 2019-09-24 12:47:42 +03:00
parent 9eb90eea8d
commit 50feeed8bf
3 changed files with 28 additions and 12 deletions

View File

@ -47,6 +47,33 @@ export default {
return comment.id === updatedComment.id ? updatedComment : comment
})
},
scrollCommentsIntoView() {
if (!window || !document) {
return
}
const container = document.getElementById('comments')
if (container) {
const top = container.offsetTop
window.scroll({
top,
left: 0,
behavior: 'smooth',
})
}
},
},
watch: {
$route(to, from) {
// scroll inside the same page
if (to.hash === '#comments') {
this.scrollCommentsIntoView()
}
},
},
mounted() {
if (this.$route.hash === '#comments') {
setTimeout(this.scrollCommentsIntoView, 250)
}
},
}
</script>

View File

@ -77,17 +77,6 @@ export default {
]
},
},
watch: {
$route(to, from) {
if (to.hash === '#comments') {
window.scroll({
top: document.getElementById('comments').offsetTop,
left: 0,
behavior: 'smooth',
})
}
},
},
}
</script>

View File

@ -193,7 +193,7 @@ export default {
.ds-card-image {
img {
max-height: 300px;
height: 300px;
object-fit: cover;
object-position: center;
}