Add variable for scrolling posts into view

This commit is contained in:
Alex Thomassen 2023-09-30 13:03:32 +00:00
parent 00357f444c
commit 32161bea62
Signed by: Alex
GPG Key ID: 10BD786B5F6FF5DE

12
blog.js
View File

@ -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.