Skip to content

Commit 5586502

Browse files
committed
UX: Only scroll if the element is not in viewport.
1 parent eaf7746 commit 5586502

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

app/assets/javascripts/discourse/controllers/topic.js.es6

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import DiscourseURL from 'discourse/lib/url';
1010
import { categoryBadgeHTML } from 'discourse/helpers/category-link';
1111
import Post from 'discourse/models/post';
1212
import debounce from 'discourse/lib/debounce';
13+
import isElementInViewport from "discourse/lib/is-element-in-viewport";
1314

1415
export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, {
1516
composer: Ember.inject.controller(),
@@ -864,9 +865,9 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, {
864865
_scrollToPost: debounce(function(postNumber) {
865866
const $post = $(`.topic-post article#post_${postNumber}`);
866867

867-
if ($post.length === 0) return;
868+
if ($post.length === 0 || isElementInViewport($post)) return;
868869

869-
$('body').animate({ scrollTop: $post.offset().top }, 1000);
870+
$('body').animate({ scrollTop: $post.offset().top - $post.height() }, 1000);
870871
}, 500),
871872

872873
unsubscribe() {

0 commit comments

Comments
 (0)