Skip to content

Commit

Permalink
fix the bug with scrolling post comments into view
Browse files Browse the repository at this point in the history
  • Loading branch information
vbelolapotkov committed Sep 24, 2019
1 parent 9eb90ee commit 50feeed
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
27 changes: 27 additions & 0 deletions webapp/components/CommentList/CommentList.vue
Expand Up @@ -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>
11 changes: 0 additions & 11 deletions webapp/pages/post/_id.vue
Expand Up @@ -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>

Expand Down
2 changes: 1 addition & 1 deletion webapp/pages/post/_id/_slug/index.vue
Expand Up @@ -193,7 +193,7 @@ export default {
.ds-card-image {
img {
max-height: 300px;
height: 300px;
object-fit: cover;
object-position: center;
}
Expand Down

0 comments on commit 50feeed

Please sign in to comment.