Introduction to the Intersection Observer JavaScript API

แชร์
ฝัง
  • เผยแพร่เมื่อ 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 TH-cam 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.

  • @stefanallchorne8667
    @stefanallchorne8667 5 ปีที่แล้ว +39

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

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

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

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

  • @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!!

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

  • @Isabela-pj3bz
    @Isabela-pj3bz 4 ปีที่แล้ว +1

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

  • @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!

  • @marcod.643
    @marcod.643 5 ปีที่แล้ว +1

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

  • @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!

  • @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 ❤️

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

  • @gergopeto3554
    @gergopeto3554 ปีที่แล้ว

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

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

  • @NoahNobody
    @NoahNobody 4 ปีที่แล้ว +1

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

  • @Fooljuice
    @Fooljuice 2 ปีที่แล้ว

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

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

  • @lawrenlelko
    @lawrenlelko 4 ปีที่แล้ว +1

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

  • @milanm6538
    @milanm6538 5 ปีที่แล้ว +1

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

  • @frankdrolet9439
    @frankdrolet9439 3 ปีที่แล้ว

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

    • @danisob3633
      @danisob3633 3 ปีที่แล้ว

      hello fellow time traveler

  • @walidali3495
    @walidali3495 11 หลายเดือนก่อน

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

  • @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);
    }

  • @GamingBeast-nq9oo
    @GamingBeast-nq9oo 5 ปีที่แล้ว

    Again, A Super Awesome Tutorial! Love It!

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

  • @FreeHindiAdvice
    @FreeHindiAdvice 2 ปีที่แล้ว

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

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

  • @Shin-oj6mo
    @Shin-oj6mo 2 ปีที่แล้ว

    This helps me a lot. Thank you!

  • @gambomaster
    @gambomaster 4 ปีที่แล้ว

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

  • @djwave28
    @djwave28 3 ปีที่แล้ว

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

  • @gnsp75
    @gnsp75 4 ปีที่แล้ว

    Really clever explanations, thank you very much!

  • @alinawaz4034
    @alinawaz4034 5 ปีที่แล้ว +1

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

  • @jaday4230
    @jaday4230 2 ปีที่แล้ว

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

  • @Daniel-ij2xy
    @Daniel-ij2xy ปีที่แล้ว

    Really useful and interesting video! Thank you!

  • @parasarora5869
    @parasarora5869 5 ปีที่แล้ว +1

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

  • @sahajkapoor4718
    @sahajkapoor4718 4 ปีที่แล้ว

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

  • @ganeshpatil6020
    @ganeshpatil6020 2 ปีที่แล้ว

    Thank you so much. I learned something new today.

  • @germanduterte7110
    @germanduterte7110 4 ปีที่แล้ว

    Very excellent demonstration. Thanks you

  • @bartek4033
    @bartek4033 4 ปีที่แล้ว

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

  • @vinigarcia
    @vinigarcia 4 ปีที่แล้ว

    Awesome explanation! Thank you very much!

  • @iglesiasleonardo1742
    @iglesiasleonardo1742 3 ปีที่แล้ว

    Great video! Thank you!

  • @avinashmurmu9070
    @avinashmurmu9070 3 ปีที่แล้ว

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

  • @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 :)

  • @ajmaljoiya6006
    @ajmaljoiya6006 3 ปีที่แล้ว

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

  • @VideoNOLA
    @VideoNOLA 3 หลายเดือนก่อน

    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!

  • @3xtraspicy
    @3xtraspicy 3 ปีที่แล้ว

    awesome explanation! Thank you for sharing!

  • @camilogarcia1325
    @camilogarcia1325 4 ปีที่แล้ว

    THANK YOU!!! Best explanation ever!

  • @user-se6ct5zu2f
    @user-se6ct5zu2f ปีที่แล้ว

    i love the way you explain!!!

  • @rasmadrak
    @rasmadrak 4 ปีที่แล้ว

    Very nice and clean explanation. Thanks! :)

  • @luismiguelrodriguez4561
    @luismiguelrodriguez4561 5 ปีที่แล้ว

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

  • @busyrand
    @busyrand 5 ปีที่แล้ว

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

  • @cristianfz16
    @cristianfz16 3 ปีที่แล้ว

    Amazing thankyou so much for this tutorial!

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

  • @GiancarloCarccamo
    @GiancarloCarccamo 2 ปีที่แล้ว

    great video, thanks for share your knowledges with us

  • @rebeka1212100
    @rebeka1212100 5 ปีที่แล้ว

    Very informative for me , thank you man 🔥🔥👌

  • @snowman_web_design_development
    @snowman_web_design_development 2 ปีที่แล้ว

    Fantastic explanation!

  • @parisamt990
    @parisamt990 2 ปีที่แล้ว

    thank you very much for this amazing video

  • @nathandowner6007
    @nathandowner6007 5 ปีที่แล้ว

    Very informative, thanks!

  • @adityabhave4053
    @adityabhave4053 5 ปีที่แล้ว

    Thanks Kevin. This is very interesting.

  • @fidansuleymanova5436
    @fidansuleymanova5436 3 ปีที่แล้ว +1

    It is great explanation. Thank you!

  • @fidansuleymanova5436
    @fidansuleymanova5436 4 ปีที่แล้ว

    It was very helpful. Thanks a lot)

  • @iqwebserve3973
    @iqwebserve3973 2 ปีที่แล้ว

    Great video, thanks.

  • @SarbbottamBandyopadhyay
    @SarbbottamBandyopadhyay 3 ปีที่แล้ว

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

  • @bhuvans9042
    @bhuvans9042 2 ปีที่แล้ว

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

  • @bokimitrovic9269
    @bokimitrovic9269 3 ปีที่แล้ว

    Thanks man, you are making most useful videos ever!

    • @KevinPowell
      @KevinPowell  3 ปีที่แล้ว

      Thanks, glad you enjoyed it :D

  • @swarnavaghosh9555
    @swarnavaghosh9555 4 ปีที่แล้ว

    Wonderful video, Kevin! Keep up the good work!

  • @MrGreenpaulo
    @MrGreenpaulo 4 ปีที่แล้ว

    Brilliant Kevin! Thanks

  • @dachd
    @dachd 4 ปีที่แล้ว

    Blew my mind! Thx

  • @awaisfiaz8186
    @awaisfiaz8186 4 ปีที่แล้ว

    Awesome exactly what i needed

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

  • @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!

  • @mythm2063
    @mythm2063 2 ปีที่แล้ว

    Thank you a lot !

  • @shinmini99
    @shinmini99 ปีที่แล้ว

    Thanks for awesome video🔥🔥

  • @franco-cespi
    @franco-cespi 3 ปีที่แล้ว

    Awesome explanation ation!

  • @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!

  • @tommy10436
    @tommy10436 ปีที่แล้ว

    Great video.
    Thanks dad.

  • @alexou857
    @alexou857 3 ปีที่แล้ว

    Wow, that is so cool, thank you :)

  • @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!

  • @hoshiskychannel3054
    @hoshiskychannel3054 4 ปีที่แล้ว

    i love your working, Kevin, from VietNam

  • @mrMinstrel
    @mrMinstrel 5 ปีที่แล้ว

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

  • @propertunity
    @propertunity 4 ปีที่แล้ว +9

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

  • @realsakul
    @realsakul 4 ปีที่แล้ว

    Thanks Kevin!

  • @mahdimotallebi7207
    @mahdimotallebi7207 2 ปีที่แล้ว

    Amazing content!

  • @J90JAM
    @J90JAM 3 ปีที่แล้ว

    This is a game changer 🙌

  • @frank3481
    @frank3481 3 ปีที่แล้ว

    Nice. Thanks

  • @sherifsalah5563
    @sherifsalah5563 5 ปีที่แล้ว

    Omg i can't wait till next week 😭

  • @SumitKumar-tw4qe
    @SumitKumar-tw4qe 4 ปีที่แล้ว

    THIS IS AWESOME.

  • @jacobbannier
    @jacobbannier 4 ปีที่แล้ว +5

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

  • @awal14h
    @awal14h ปีที่แล้ว

    i like tho "pop" sound effect you made haha

  • @lebsyt3892
    @lebsyt3892 3 ปีที่แล้ว

    Cool vid tnx for sharing 🥰

  • @michael.a.strauss
    @michael.a.strauss 5 ปีที่แล้ว +5

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

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

  • @eduardoaviles357
    @eduardoaviles357 2 ปีที่แล้ว

    Still the best explanation how intersection observers work.

  • @RazahLP
    @RazahLP 2 ปีที่แล้ว

    Thanks! 🙂

  • @aqua123670
    @aqua123670 5 ปีที่แล้ว

    thank you ! please do more JS videos

  • @sumanth3036
    @sumanth3036 4 ปีที่แล้ว

    Thanks a lot.