Create an Infinite Scroll | Lazy Loading Page

  Рет қаралды 43,970

Steve Griffith - Prof3ssorSt3v3

Steve Griffith - Prof3ssorSt3v3

5 жыл бұрын

This tutorial explains how you can easily create your own lazy loading page or infinite scrolling page with JavaScript and the Intersection Observer API.
Intro to InterSectionObserver video: • IntersectionObserver API
Sample Code GIST: gist.github.com/prof3ssorSt3v...

Пікірлер: 65
@iwswordpress
@iwswordpress 5 жыл бұрын
awesome! Thanks for introducing things I would not know existed.
@Suneriins234
@Suneriins234 4 жыл бұрын
I love to watch your videos.Fantastic understanding!
@gladstonross12
@gladstonross12 5 жыл бұрын
Just another reason why keep going.. Love your vids
@frankgute4456
@frankgute4456 2 жыл бұрын
Just wow. You are professional please keep give us something wonderful like this . big heart from germany
@supa1009
@supa1009 4 жыл бұрын
elegant solution. thanks steve!
@CarloNyte
@CarloNyte 3 жыл бұрын
So freaking helpful! Thank you!!
@MicahJohns
@MicahJohns 4 жыл бұрын
Would be awesome to see a version of this that extracts the data from a MYSQLI database, regardless.. thank you for making this.
@benvance3716
@benvance3716 2 жыл бұрын
I guess Im asking the wrong place but does anyone know a trick to get back into an Instagram account?? I was dumb forgot the login password. I would love any tricks you can give me
@shepardgrey6618
@shepardgrey6618 2 жыл бұрын
@Ben Vance instablaster =)
@benvance3716
@benvance3716 2 жыл бұрын
@Shepard Grey I really appreciate your reply. I got to the site thru google and im waiting for the hacking stuff atm. I see it takes a while so I will reply here later when my account password hopefully is recovered.
@benvance3716
@benvance3716 2 жыл бұрын
@Shepard Grey It worked and I actually got access to my account again. I'm so happy! Thank you so much you saved my ass!
@shepardgrey6618
@shepardgrey6618 2 жыл бұрын
@Ben Vance glad I could help :D
@FordExplorer-rm6ew
@FordExplorer-rm6ew 4 жыл бұрын
Can you have 2 intersection observers? I have one that observes section tags and places a bubble of the same color over my nav links. Are there cases where people use two? Or would you just pass another function in before options?
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 4 жыл бұрын
It would be more efficient to put all the functionality inside one function if possible.
@shinej11
@shinej11 4 жыл бұрын
Hi Steve, thank you for sharing this. I love your videos :) I am trying to implement this on a table to load rows as you scroll. I tried setting the target as '#myTable tr:last-child'. It is getting triggered and loading contents, however not working as expected. Would you have any suggestions? thank you
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 4 жыл бұрын
Without knowing what it is doing I can't really say. Are you adding a new row or just adding more content to the existing last row?
@shinej11
@shinej11 4 жыл бұрын
@@SteveGriffith-Prof3ssorSt3v3 I've got a table with more than 500 rows; data obtained from API in JSON format. I am working on my first PWA. Loading all the rows at first is affecting the performance of the app. Any suggestions? Thank you for replying, Steve :)
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 4 жыл бұрын
500 objects is not a lot of data. The performance is likely being impacted by rendering that many rows. You can get the data with one fetch and then add them in chunks as the user scrolls.
@shinej11
@shinej11 4 жыл бұрын
@@SteveGriffith-Prof3ssorSt3v3 Thank you, Steve :) Appreciate it
@andrewtanjaya8263
@andrewtanjaya8263 4 жыл бұрын
I dont understand about how you can limit your getdata function to get data until the footer is intersecting, mine it will fetch all data at once
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 4 жыл бұрын
Each of my fetch calls gets another copy of the same json file. I am not limited the results from that JSON file. I am just adding more copies of the same data. To be able to limit you need to be calling an API that allows for limiting and paging of results. That is server-side functionality though.
@GuitaristZep
@GuitaristZep Жыл бұрын
This still detects an element that has a property of "display:none" or is within a parent element with a property of "display:none". Can you help me solve this problem?
@BottomTheoryTV
@BottomTheoryTV 2 жыл бұрын
I'm trying to fetch photos from my documents folder but it's not working. Can you help pleases?
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 2 жыл бұрын
You can't "fetch" from local files. Security restrictions.
@XXX-nd2zz
@XXX-nd2zz 2 жыл бұрын
Should we also consider about recycling some nodes as the scroll grows bigger?
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 2 жыл бұрын
When working with an infinite scroll situation you always need to consider how much data COULD get loaded. If you are using the Lighthouse tools in Chrome to test your page then you will get warnings about excessive DOM size if you exceed: - over 1,500 DOM nodes in total - a maximum node-depth greater than 32 nodes - greater than 60 child nodes exist in a single branch. This last one pertains to infinite scrolling the most. Now, obviously an infinite scrolling page is likely to exceed 60 new items added as the user scrolls. However, the impact of that will vary GREATLY depending on the device loading the resources. The new upcoming media query prefers-reduced-data is something to consider using to limit infinite scrolling. You can definitely use JS to remove elements from the top as you scroll down and vice-versa while scrolling up. Just a matter of managing a single source of truth for the data and tying in to your scrolling to load and unload. A good recycler view is a lot of work though. Here is a good article about it - developers.google.com/web/updates/2016/07/infinite-scroller
@XXX-nd2zz
@XXX-nd2zz 2 жыл бұрын
@@SteveGriffith-Prof3ssorSt3v3 omg!! thanks for the reply and I didn't expect your quick response ☺!! subscribed!!
@coderdoctor
@coderdoctor 2 жыл бұрын
Sir thanks for this content😃
@ramisanawar9697
@ramisanawar9697 4 жыл бұрын
Sir. After log in fb with javascript or python or php or any other sources is it possible to speedly or rapidly scroll down into a fb group? I need to copy all posts and comments of a group at very short time.
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 4 жыл бұрын
They only load a few at a time for better performance. Maybe if you look into the FB API you can find methods to do that
@kirillbaryba746
@kirillbaryba746 5 жыл бұрын
Hi Steve, you have a video how to implement ajax pagination, how to do it correctly? Thanks
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 5 жыл бұрын
No I dont yet. Please add that to my tutorial request video comments
@fsbgaming1588
@fsbgaming1588 4 жыл бұрын
@@SteveGriffith-Prof3ssorSt3v3 so if this used for paging the problem is when the paging end. its still fetching... how to stop it.
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 4 жыл бұрын
@@fsbgaming1588 You need to have information from the server about how many records are coming back or if it is the last page. OR if you get an empty record set from the server then you can stop doing the fetch.
@mulindierick195
@mulindierick195 4 жыл бұрын
how do I do this if I am loading the images from a database? Let's say the images are posts by a user. How do I implement this?
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 4 жыл бұрын
The same way. You will just be making ajax calls to a serverside script that returns more image urls or more html
@mulindierick195
@mulindierick195 4 жыл бұрын
@@SteveGriffith-Prof3ssorSt3v3 thank you, Let me try this
@Ayua1
@Ayua1 2 жыл бұрын
Hello Steve, please does this work well on mobile phones browsers. I have an issue with loading more content on my website. It works well on desktop browsers but doesn't work on mobile phone browsers except for Safari.
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 2 жыл бұрын
If you are on iOS, Apple requires all browsers to use the safari webkit engine. If it works on Safari then the script should run on all browsers on iOS.
@mustafaneto26
@mustafaneto26 2 жыл бұрын
Hello Steve, this works really well here, but if I go to another link and return It breaks, do you know what problem should it be?
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 2 жыл бұрын
I'm not having that problem. What part is breaking exactly? Are there error messages in the console?
@kathirvelv7798
@kathirvelv7798 3 жыл бұрын
How can we handled the large list of data and DOM?
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 3 жыл бұрын
We should be fetching small amounts of data and adding that to the DOM. As for the size of the page that is only limited by the amount of memory available in the device.
@zroot
@zroot Жыл бұрын
Hi Steve, Thanks for sharing. Its seems essay, you have a array of 4 objects and you fetch them again and again. But I have a array of 200 objects. How can I fetch first 4 objects, then first 4 objects with second 4 objects and then first, second and third 4 objects. and so on.. I'm a little noob to JavaScript, so please describe a little wordily. Thank you
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 Жыл бұрын
The 4 objects that I am loading over and over is just a place holder for the real version that would be using fetch( ) to get the hundreds of items. I have a playlist about AJAX and fetch that explains everything you need to know about getting data from a remote source to load on to a page.
@zroot
@zroot Жыл бұрын
@@SteveGriffith-Prof3ssorSt3v3 Thank you again. I watch all of the video on that playlist. It gives me a lot of knowledge about fetch and other stuff. But i didn't get what I'm looking for.. Didn't find any suitable video about How can I fetch first 4 objects, then first 4 objects with second 4 objects and then first, second and third 4 objects. and so on..
@GuitaristZep
@GuitaristZep Жыл бұрын
@@SteveGriffith-Prof3ssorSt3v3 I think he is talking about setting and using the offset for the lazyload because it is not discussed here sir
@YouCodeRK
@YouCodeRK 11 ай бұрын
If an API supports pagination then you can use query parameter for requesting only limited data from API and can calculate the prev loaded data and can request for next data on the basis of pageNo, itemsPerPage. check the documentation of the API used for pagination support
@adhigeorgevlogs
@adhigeorgevlogs Жыл бұрын
Ever faced an issue where it triggered the callback twice in safari?
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 Жыл бұрын
The Intersection observer will be called potentially many many times in all browsers.
@shyamtailor4762
@shyamtailor4762 4 жыл бұрын
sir how get images from our system not internet
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 4 жыл бұрын
Sorry. Dont understand your question.
@bautistadalisaymilenem.4722
@bautistadalisaymilenem.4722 3 жыл бұрын
how can I insert my own images and captions?
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 3 жыл бұрын
Use fetch() to get the data from somewhere like your own data source. Then the content you build will be your own.
@bautistadalisaymilenem.4722
@bautistadalisaymilenem.4722 3 жыл бұрын
@@SteveGriffith-Prof3ssorSt3v3 thank you so much
@semosemo3827
@semosemo3827 2 жыл бұрын
why there is 3 images each line always ?
@semosemo3827
@semosemo3827 2 жыл бұрын
it's because 'grid-template-columns'
@altonmazin
@altonmazin 4 жыл бұрын
how are you fetching only 4 elements?
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 4 жыл бұрын
There are only 4 in the JSON that I fetch - gist.githubusercontent.com/prof3ssorSt3v3/1944e7ba7ffb62fe771c51764f7977a4/raw/c58a342ab149fbbb9bb19c94e278d64702833270/infinite.json
@ssyo5450
@ssyo5450 4 жыл бұрын
please share me images JSON file
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 4 жыл бұрын
The URL for the JSON is in the code that is linked to in the description.
@kaan9631
@kaan9631 3 жыл бұрын
Turkey yazıyor footerda as bayrakları as
DOM Element matches and closest methods
12:01
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 6 М.
Learn Infinite Scroll in JavaScript
14:11
The Code Creative
Рет қаралды 28 М.
What it feels like cleaning up after a toddler.
00:40
Daniel LaBelle
Рет қаралды 87 МЛН
You are loading Images wrong! Use this instead 😍
14:41
CoderOne
Рет қаралды 211 М.
3 Ways To Scrape Infinite Scroll Sites with Playwright
12:19
John Watson Rooney
Рет қаралды 19 М.
CSS Anchor Is The Best New CSS Feature Since Flexbox
15:39
Web Dev Simplified
Рет қаралды 363 М.
Angular Infinite Scroll Example Using ngx-infinite-scroll
23:11
coderspirit
Рет қаралды 29 М.
Create an infinite horizontal scroll animation
32:01
Kevin Powell
Рет қаралды 189 М.
Lazy loading is too easy now
16:05
Kevin Powell
Рет қаралды 146 М.
Using FormData Objects Effectively
13:14
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 36 М.
Revealing the Differences between HTML Dialogs and the Popover API
24:14
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 8 М.
Top 10 CSS One Liners That Will Blow Your Mind
13:34
developedbyed
Рет қаралды 932 М.
What it feels like cleaning up after a toddler.
00:40
Daniel LaBelle
Рет қаралды 87 МЛН