From 32161bea628c6b45fcf86af524fa80e38fa78c1f Mon Sep 17 00:00:00 2001 From: Alex Thomassen Date: Sat, 30 Sep 2023 13:03:32 +0000 Subject: [PATCH] Add variable for scrolling posts into view --- blog.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/blog.js b/blog.js index f96b6b5..6023185 100644 --- a/blog.js +++ b/blog.js @@ -16,6 +16,16 @@ const postsContainerSelector = '#blog-posts'; */ const viewMoreButtonSelector = '#view-more'; +/** + * When clicking "View more" to retrieve posts on page 2 and beyond + * set this to `true` to scroll to the first post of the new batch of posts. + * + * If you do not want this behavior, set this to `false`. + * + * By default this is `true`. + */ +const scrollToPosts = true; + /** * Classes to add to the post's parent div. * By default these are Tailwind CSS classes: https://tailwindcss.com/ @@ -136,7 +146,7 @@ async function getPosts() * Style points only * Only trigger this logic after the "view more" button has been pressed */ - if (nextPage > 1) { + if (nextPage > 1 && scrollToPosts) { /** * Style points only * Scroll to the first post we got from the API.