Introduction to the Intersection Observer JavaScript API

Поделиться
HTML-код
  • Опубликовано: 11 июн 2019
  • You can find the code here: • Introduction to the In...
    Use the following link to get 2 FREE months to Skillshare: skl.sh/kevinpowell4
    Intersection Observer is a JavaScript API that we can use to do a lot of really useful things that we used to have to rely on scroll event listeners for. Instead of firing off over and over and over again on tons of items, they sit there and wait for their target intersect with the page before firing.
    We can use them to watch for when things enter or leave the viewport, and we can play with the options to change how much of the item has entered (the threshold), or how far into the page it is (the rootMargin).
    In this video we're exploring the fundamentals of how they work so that in the following weeks we can start having fun with them!
    This video was sponsored by Skillshare.
    #javascript #intersectionobserver
    ---
    Come and hangout, ask questions, suggest ideas, and meet some awesome people over in The Community: / discord
    I have a newsletter! www.kevinpowell.co/newsletter
    New to Sass, or want to step up your game with it? I've got a course just for you: www.kevinpowell.co/learn-sass
    ---
    My Code Editor: VS Code - code.visualstudio.com/
    How my browser refreshes when I save: • How to automatically r...
    ---
    Support me on Patreon: / kevinpowell
    I'm on some other places on the internet too!
    If you'd like a behind the scenes and previews of what's coming up on my RUclips channel, make sure to follow me on Instagram and Twitter.
    Instagram: / kevinpowell.co
    Twitter: / kevinjpowell
    Codepen: codepen.io/kevinpowell/
    Github: github.com/kevin-powell

Комментарии • 258

  • @bobmarteal
    @bobmarteal 4 года назад +9

    Kevin, the amount of content you pick for each video is perfect. Much more than what you covered would swamp people. Great example and explanation.

  • @jesseearley2019
    @jesseearley2019 3 года назад +22

    Thank you for this straightforward and easy to understand video. This allowed me to accomplish EXACTLY what I've been trying to figure out how to do, which in my case was perform some simple animation for elements as the user scrolled down the page.

  • @anawhite2562
    @anawhite2562 4 года назад +3

    Thank you so much! One new thing I learned today after watching this video: unobserve() will stop observing a specified element, while disconnect() will stop observing all of them.

  • @annasognosia
    @annasognosia Год назад +1

    Kevin is a pleasure to listen to. I'm grateful to anyone who posts any level of understanding but Kevin makes it easier by explaining how it works.

  • @stefanallchorne8667
    @stefanallchorne8667 5 лет назад +39

    This video is so good. Came at the perfect time. Thanks Kevin!!

  • @MrAnmoltiwari
    @MrAnmoltiwari 4 года назад +12

    This is extraordinary to be honest. The way you explain it is just so easy on the brain!

  • @dan110024
    @dan110024 2 года назад

    This finally simplified everything after an afternoon of trying to work out intersection observer by reading. Amazing.

  • @tanishqmanuja
    @tanishqmanuja 5 лет назад +6

    You always bring such creative content with most practical and easy to learn JS implementations .Best channel for learning Web Development

  • @buchiolisa3878
    @buchiolisa3878 4 года назад

    I always like your videos before I watch it and I have never been disappointed. Great job Kevin and thank you for this ❤️

  • @chrisallen3807
    @chrisallen3807 4 года назад +2

    Extremely clear and helpful video. I'm going to use the intersectionObserver from here on out for work. No more annoying scroll listeners!!

  • @hsdev
    @hsdev 3 года назад +3

    Thanks so much for explaining this with such clarity and detail. I was trying to wrap my head around this API and your video really helped me get it. Thank You!

  • @jaymesinn5134
    @jaymesinn5134 2 года назад

    This video and your second on the topic really helped me out with a parallax fade in scroll effect I was working on for a project at work. Thabk you SO much! I love your videos and the fact you explain your methods.

  • @jenso413
    @jenso413 Год назад +1

    I haven't even watched much of the video yet and I already know it's gonna be great. Thanks so much for everything you post, I finally got a job in web dev and my company uses intersection observer API, so here I am!

  • @A_Lesser_Man
    @A_Lesser_Man 5 лет назад +2

    this is what i did with what you just taught me! thanks, Kevin!
    HTML file:
    test
    function action(entry) {
    entry.target.innerHTML = "YAHOO!";
    }
    const options = {
    root: null, // null = viewport, default
    threshold: 0, // 0 means fire observer if any bit of element enters container and 1 means if all of element is within container (may use 0.25, etc)
    rootMargin: "0px" // some arbitrary number...
    };
    const blah = newObserver("#test", options, action);
    javascript file:
    function newObserver(selector, options, entryAction, unobserve, DEBUG) {
    const element = document.querySelector(selector);
    const observer = new IntersectionObserver(function(entries, observer) {
    entries.forEach(entry => {
    if (entry.isIntersecting) {
    if (DEBUG) { console.log(entry.target); }
    // some user created function to call to do shit to the entry
    if (entryAction) { entryAction(entry); }
    if (unobserve) { observer.unobserve(entry.target); }
    }
    });
    }, options);
    observer.observe(element);
    }

  • @Isabela-pj3bz
    @Isabela-pj3bz 4 года назад +1

    So useful! I've been searching it for a while... Thanks! Wondrous content.

  • @justinoneill2837
    @justinoneill2837 4 года назад +3

    had no idea about this one! literally just decked out a project w/ scroll fx too but had to use the debounce technique. this is exactly what i was missing

  • @Fooljuice
    @Fooljuice 2 года назад

    Very useful and straightforward. You are amazing Kevin!!!

  • @gergopeto3554
    @gergopeto3554 Год назад

    Kevin! I love your videos. You are the best source on youtube what I found regarding to front end dev

  • @frankdrolet9439
    @frankdrolet9439 2 года назад

    2 years later, this video is still the best out there to explain this, thanks a lot!

    • @danisob3633
      @danisob3633 2 года назад

      hello fellow time traveler

  • @lawrenlelko
    @lawrenlelko 4 года назад +1

    It seems that this could add credibility to a portfolio page. THANK-YOU!

  • @ilan117
    @ilan117 5 лет назад +3

    Hi Kavin :-) Thank you for this video! Something interesting and new to learn ... Honestly, the way you teach/speak makes it easy to understand and follow up. Yes, I am totally waiting for the "observer" next video... hopefully I will learn how to use it for manipulating the DOM e.g. animations and so! Thank you for a wonderful content.

  • @marcod.643
    @marcod.643 5 лет назад +1

    Waiting for the next videos about this very interesting topic.
    As always great info, thanks!

  • @NoahNobody
    @NoahNobody 4 года назад +1

    Thanks, I had a really hard time understanding this from the documentation. You cleared it up nicely for me.

  • @VideoNOLA
    @VideoNOLA 2 месяца назад

    Definitely helpful for reinitializing SVG animations when the scroll into view, especially is you included a block with an embedded background-image SVG using CSS, which otherwise sandboxes them from the containing DOM!

  • @nitram_nosnibor
    @nitram_nosnibor 3 года назад

    Incredibly interesting and I can see how I can use that in many situations, thanks for sharing Kevin. Off the watch the others in this series now.

  • @walidali3495
    @walidali3495 10 месяцев назад

    you are a great developer man , thank you so much for all of your work

  • @milanm6538
    @milanm6538 5 лет назад +1

    Great content, well explained. Hope to see more of Observers

  • @jaday4230
    @jaday4230 2 года назад

    This is super easy to understand and have saved my life, thanks dude

  • @FreeHindiAdvice
    @FreeHindiAdvice 2 года назад

    One of the best video to understand Intersection observer. Thank you Kevin :) :) :)

  • @gambomaster
    @gambomaster 4 года назад

    You deserve more subscribers Kevin. Glad I am one of your subscriber. 👍👍👍

  • @Franiveliuselmago
    @Franiveliuselmago 4 года назад +1

    Thanks a lot for this explanation! I used this to give color to my nav menu items acording to the section the user is viewing.

  • @ajmaljoiya6006
    @ajmaljoiya6006 2 года назад

    Sir your explanation has boosted my knowledge about Intersection observer
    Thanks a lot

  • @mohammadalaaelghamry8010
    @mohammadalaaelghamry8010 11 месяцев назад

    Thank you so much. Such an amazing explanation. That was extremely clear and usefl.

  • @alinawaz4034
    @alinawaz4034 5 лет назад +1

    Love your videos Always like before watch Keep making those Cool JS Videos very helpful and interesting!!

  • @GamingBeast-nq9oo
    @GamingBeast-nq9oo 5 лет назад

    Again, A Super Awesome Tutorial! Love It!

  • @avinashmurmu9070
    @avinashmurmu9070 3 года назад

    crystal clear explaination ❤️ ❤️.... Thank you so much for the tutorial.

  • @ganeshpatil6020
    @ganeshpatil6020 2 года назад

    Thank you so much. I learned something new today.

  • @Shin-oj6mo
    @Shin-oj6mo 2 года назад

    This helps me a lot. Thank you!

  • @germanduterte7110
    @germanduterte7110 4 года назад

    Very excellent demonstration. Thanks you

  • @sahajkapoor4718
    @sahajkapoor4718 4 года назад

    The best tutorial i found on this topic
    PS: I have looked over a lot of them

  • @parasarora5869
    @parasarora5869 5 лет назад +1

    wow sir...you brought a new topic this time...and its related to js...its awesome 👍👍👍

  • @djwave28
    @djwave28 3 года назад

    I have Observed this!!!!!! It is now stored in my Intersection.

  • @vinigarcia
    @vinigarcia 4 года назад

    Awesome explanation! Thank you very much!

  • @einatblackrose
    @einatblackrose Год назад

    Hi Kevin, I guess I'm in a bit of a delay... but had to tell you that this video is so useful! After watching many videos trying to figure out something I was attempting to do, this was the only video that worked, and that's because I could actually understand what I'm doing rather than just copy-paste it as I normally do.
    I'm by no mean a js expert... to say the least, but you just explain so clearly.
    Somehow your videos always come to the rescue when I struggle with my codes, and I thank you a lot for it.

  • @camilogarcia1325
    @camilogarcia1325 4 года назад

    THANK YOU!!! Best explanation ever!

  • @wwt17
    @wwt17 5 лет назад +2

    This is awesome. Can't wait for all of the series!!! For beginners you might want to mention that you need to npm i intersection-observer

    • @KevinPowell
      @KevinPowell  5 лет назад +2

      I should have mentioned the polyfill for sure, but most beginners probably won't do it with npm from my experience 😁
      I'll make a video at the end of the series to talk about the polyfill, as it's probably important to mention 👍

    • @wwt17
      @wwt17 5 лет назад

      @@KevinPowell Yaaaaasss!!!

    • @justinoneill2837
      @justinoneill2837 4 года назад

      supports not to bad caniuse.com/#search=intersection

  • @Daniel-ij2xy
    @Daniel-ij2xy Год назад

    Really useful and interesting video! Thank you!

  • @user-se6ct5zu2f
    @user-se6ct5zu2f Год назад

    i love the way you explain!!!

  • @airlobster2
    @airlobster2 5 лет назад

    Didn't know such thing even existed! I went straight away to add it to a grid-based table control (tabular data view, sortable columns, expandable rows, selections, sticky headers...) I'm writing these days. works great. thanks for that :)

  • @bartek4033
    @bartek4033 4 года назад

    Thanks a lot. I have already put it all to my project !

  • @busyrand
    @busyrand 5 лет назад

    Very nice programming video. Your audio is nice and you're a very good explainer.

  • @iglesiasleonardo1742
    @iglesiasleonardo1742 3 года назад

    Great video! Thank you!

  • @luismiguelrodriguez4561
    @luismiguelrodriguez4561 5 лет назад

    Omg it is so powerful. Thanks for sharing your knowledge.

  • @snowman_web_design_development
    @snowman_web_design_development 2 года назад

    Fantastic explanation!

  • @3xtraspicy
    @3xtraspicy 3 года назад

    awesome explanation! Thank you for sharing!

  • @rasmadrak
    @rasmadrak 4 года назад

    Very nice and clean explanation. Thanks! :)

  • @cristianfz16
    @cristianfz16 3 года назад

    Amazing thankyou so much for this tutorial!

  • @fidansuleymanova5436
    @fidansuleymanova5436 3 года назад +1

    It is great explanation. Thank you!

  • @GiancarloCarccamo
    @GiancarloCarccamo 2 года назад

    great video, thanks for share your knowledges with us

  • @rebeka1212100
    @rebeka1212100 5 лет назад

    Very informative for me , thank you man 🔥🔥👌

  • @parisamt990
    @parisamt990 2 года назад

    thank you very much for this amazing video

  • @nathandowner6007
    @nathandowner6007 4 года назад

    Very informative, thanks!

  • @bhuvans9042
    @bhuvans9042 2 года назад

    Great❤️!! Thank you Sir for Posting these useful contents with good explanation.

  • @propertunity
    @propertunity 4 года назад +9

    Hey Kevin! Any chance you could show an example on how to use intersection observer with a performant parallax?

  • @bokimitrovic9269
    @bokimitrovic9269 3 года назад

    Thanks man, you are making most useful videos ever!

    • @KevinPowell
      @KevinPowell  3 года назад

      Thanks, glad you enjoyed it :D

  • @adityabhave4053
    @adityabhave4053 5 лет назад

    Thanks Kevin. This is very interesting.

  • @fidansuleymanova5436
    @fidansuleymanova5436 4 года назад

    It was very helpful. Thanks a lot)

  • @jacobbannier
    @jacobbannier 4 года назад +5

    Starts at 02:50// Just watched the video, really clear and easy to follow. Thanks :)

  • @SarbbottamBandyopadhyay
    @SarbbottamBandyopadhyay 3 года назад

    Thank you for the video, very informative, and great explanation.

  • @iqwebserve3973
    @iqwebserve3973 2 года назад

    Great video, thanks.

  • @arabianoud313
    @arabianoud313 4 года назад

    Thank you for making this. I've been struggling with trying to figure this all out based on the MDN documentation alone. I've already started applying this to my project after watching this. Great intro!

  • @franco-cespi
    @franco-cespi 3 года назад

    Awesome explanation ation!

  • @shinmini99
    @shinmini99 Год назад

    Thanks for awesome video🔥🔥

  • @MrGreenpaulo
    @MrGreenpaulo 4 года назад

    Brilliant Kevin! Thanks

  • @awaisfiaz8186
    @awaisfiaz8186 4 года назад

    Awesome exactly what i needed

  • @swarnavaghosh9555
    @swarnavaghosh9555 4 года назад

    Wonderful video, Kevin! Keep up the good work!

  • @elderf
    @elderf Год назад

    This was great. I was trying to understand how scrollama.js works and this makes a lot of sense. In a way, I could just use the Intersection Observer API instead of the library if I wanted to go with Vanilla JS.

  • @tf7788
    @tf7788 3 года назад

    Great, thanks for sharing this ! I was going to use some libraries but with this, I will do my own animations and don't use any !

  • @user-mo3cw6go7c
    @user-mo3cw6go7c 2 года назад

    Perfect intro!

  • @mrMinstrel
    @mrMinstrel 5 лет назад

    Great! Now all the pieces begin to fit together...

  • @dachd
    @dachd 4 года назад

    Blew my mind! Thx

  • @eduardoaviles357
    @eduardoaviles357 2 года назад

    Still the best explanation how intersection observers work.

  • @hoshiskychannel3054
    @hoshiskychannel3054 4 года назад

    i love your working, Kevin, from VietNam

  • @mahdimotallebi7207
    @mahdimotallebi7207 2 года назад

    Amazing content!

  • @tommy10436
    @tommy10436 11 месяцев назад

    Great video.
    Thanks dad.

  • @michael.a.strauss
    @michael.a.strauss 5 лет назад +5

    Good stuff! Any place to get those original CSS and HTML files to "play along"? ;-)

  • @mythm2063
    @mythm2063 2 года назад

    Thank you a lot !

  • @J90JAM
    @J90JAM 3 года назад

    This is a game changer 🙌

  • @ezekielswanson7813
    @ezekielswanson7813 2 года назад

    Hey Kevin, thank you so much for the video. This was awesome. Just a heads up the link that's suppose to go to the code goes to back to your youtube video!

  • @lebsyt3892
    @lebsyt3892 3 года назад

    Cool vid tnx for sharing 🥰

  • @alexou857
    @alexou857 3 года назад

    Wow, that is so cool, thank you :)

  • @aqua123670
    @aqua123670 5 лет назад

    thank you ! please do more JS videos

  • @angellfoto
    @angellfoto 3 года назад

    Hi Kevin. Thanks for lot of nice and useful videos! Lets say i have 3 cards per row, how is it possible to delay each card displayed before the next one?

  • @peter8261
    @peter8261 Год назад

    Very cool. I'm working on an animated CSS project and I only know a very small amount of JS. I'm trying to animate things upon scroll, and i think this is going to be my solution.

  • @SumitKumar-tw4qe
    @SumitKumar-tw4qe 4 года назад

    THIS IS AWESOME.

  • @realsakul
    @realsakul 4 года назад

    Thanks Kevin!

  • @frank3481
    @frank3481 3 года назад

    Nice. Thanks

  • @awal14h
    @awal14h Год назад

    i like tho "pop" sound effect you made haha

  • @sherifsalah5563
    @sherifsalah5563 5 лет назад

    Omg i can't wait till next week 😭

  • @prashantchaubey2805
    @prashantchaubey2805 11 месяцев назад

    Thank you