- This topic has 8 replies, 3 voices, and was last updated 6 years, 8 months ago by
Tom.
-
AuthorPosts
-
June 13, 2019 at 11:51 am #928749
madmanweb
Hi.
How can I add a “loading” spinner GIF to the infinite scroll feature? Sometimes my scroll is smooth and seamless but sometimes it seems to take forever and I don’t want people to think they’ve reached the end of the content.
June 13, 2019 at 11:55 am #928753Leo
StaffCustomer SupportHi there,
There should be a spinning icon by default with the Loading Label option:
https://docs.generatepress.com/article/blog-content-layout/#archivesHave you tried that yet?
Let me know 🙂
June 13, 2019 at 8:43 pm #929056madmanweb
That option adds a “Load more” button instead of constantly loading posts while scrolling down. So it’s not what I’m looking for.
June 13, 2019 at 8:44 pm #929057madmanweb
Here is an example of what I mean: https://infiniteajaxscroll.com/examples/basic/page1.html
When you scroll, a loading spinner activates while the content is being fetched.
June 14, 2019 at 8:44 am #929728Tom
Lead DeveloperLead DeveloperHi there,
First, you would need to add your loading icon to the site.
1. Create a Hook Element: https://docs.generatepress.com/article/hooks-element-overview/
2. Set the Hook toafter_main_content
3. Set the priority to100
4. Add this content:<div class="infinite-loading" style="display: none;"> Loading... </div>Then you need to add javascript to show the icon as things load:
jQuery( document ).ready( function($) { var $container = $( '#main article' ).first().parent(); $container.on( 'request.infiniteScroll', function( event, response, path, items ) { $( '.infinite-loading' ).show(); } ); $container.on( 'append.infiniteScroll', function( event, response, path, items ) { $( '.infinite-loading' ).hide(); } ); } );If you don’t have a place to add javascript, you can:
1. Create a Hook Element: https://docs.generatepress.com/article/hooks-element-overview/
2. Set the hook towp_footer
3. Add the above javascript within<script>tags like this:<script> // Javascript above </script>Let me know if you need more info 🙂
June 16, 2019 at 7:06 am #931389madmanweb
Hmm, so this partially works, Tom. The problem is that the “Loading” DIV appears only after the first batch of posts. After you’ve scrolled to the bottom of the next X posts, it doesn’t appear any more. I’ve checked this using the Chrome dev tools in the code. Only one instance of “Loading” found.
June 16, 2019 at 8:50 am #931459Tom
Lead DeveloperLead DeveloperIs this currently added to your website? I’m not seeing the loading div at all.
Let me know 🙂
June 16, 2019 at 9:11 am #931483madmanweb
Hi. Yeah, I added it to another site. Over here: https://wordpress-151076-839570.cloudwaysapps.com/
Should show every 3 posts after the main featured post.
June 16, 2019 at 3:43 pm #931685Tom
Lead DeveloperLead DeveloperHmm, can you try the
after_primary_content_areainstead? -
AuthorPosts
- You must be logged in to reply to this topic.