IntersectionObserver?! Scroll Activated Animations & More with No Dependencies

Sdílet
Vložit
  • čas přidán 30. 07. 2019
  • promo.linode.com/designcourse/ - Use code 'DESIGNC19' to get $20 credit on your new Linode account!
    designcourse.com - Learn UI/UX from Scratch with my new service (coming soon)
    -- Today, we're going to take a look at something called the Intersection Observer, which is a fancy way of describing how to determine when certain HTML elements come into view. You can then do stuff like attach CSS styles, classes, and other stuff. This will allow you to do things like scroll activated animations, lazy loading images, etc.. All of this is without any third party scripts.
    Codepen demo:
    codepen.io/designcourse/pen/R...
    Link referenced in the video:
    developer.mozilla.org/en-US/d...
    Let's get started!
    - - - - - - - - - - - - - - - - - - - - - -
    Subscribe for NEW VIDEOS!
    My site: designcourse.com
    My personal FB account: logodesigner
    Coursetro FB: coursetro
    Coursetro's Twitter: / designcoursecom
    Join my Discord! / discord
    ^-Chat with me and others
    - - - - - - - - - - - - - - - - - - - - - -
    Who is Gary Simon? Well, I'm a full stack developer with 2+ decades experience and I teach people how to design and code. I've created around 100+ courses for big brands like LinkedIn, Lynda.com, Pluralsight and Envato Network.
    Now, I focus all of my time and energy on this channel and my website Coursetro.com.
    Come to my discord server or add me on social media and say Hi!
  • Jak na to + styl

Komentáře • 89

  • @DesignCourse
    @DesignCourse  Před 5 lety +26

    What are you doing? Sub up already!

    • @IllusionIRL
      @IllusionIRL Před 5 lety

      Damn dude nice one again, my another youtubers Grafikart make this aswell in french but both version together is better !

    • @fatimafadou4295
      @fatimafadou4295 Před 5 lety

      I do not understand Why did you do foreach image in images

    • @Rafael-ky5hw
      @Rafael-ky5hw Před 4 lety

      done.

    • @scottonanski4173
      @scottonanski4173 Před 3 lety

      Pro-tip: ctrl+r.
      Love ya. :)

    • @silaszayne6343
      @silaszayne6343 Před 2 lety

      instablaster...

  • @peepwebdev575
    @peepwebdev575 Před 4 lety +20

    If anyone is struggling to get the staggered animations to work at the end. Make sure your using backtick. He said it really quickly so easy to miss. I'm new to JS so i had no idea there is a difference between ` and ' .
    This is for: `anim1 2s ${entry.target.dataset.delay} forwards ease-out`

  • @dotsona07
    @dotsona07 Před 5 lety +41

    JavaScript has been really killing it lately. So happy I don't have to use plugins to do this stuff anymore.

  • @kaungkhantzaw4979
    @kaungkhantzaw4979 Před 5 lety +7

    I was about to create a small project using intersection observer from other tutorials and you upload the tutorial ! FeelsGoodMan

  • @elmersbalm5219
    @elmersbalm5219 Před 4 lety +4

    thanks for keeping in the mistakes. Coding is frustrating and hard, seeing a polished tutorial is beyond frustrating!

  • @preet8457
    @preet8457 Před 5 lety +14

    WOW, I was looking for this for ages. Finally, I got it. thank you. Vanilla JS is awesome.

    • @spiderous
      @spiderous Před 4 lety +1

      Finally we have good programming experience without using third party libraries as JQuery to make it convenient to use. :)

  • @JeffThePoustman
    @JeffThePoustman Před 4 lety +2

    HTML-CSS Setup 0:00
    JS Setup 10:08
    Intersection Observer Setup 11:54
    Thanks for the helpful tutorial. I do like that you have all the setup in there-- it helps orient me the viewer, ensures that the whole thought process is explained. I added times for repeat viewing, as I want to go over the IO material again.

  • @rafalpotasz
    @rafalpotasz Před 5 lety +3

    This is crazy useful. I haven’t written a line of JS yet, I’m just building my understanding of positioning and shape manipulations in CSS first but this is going to be the first thing I try in JS after learning some basics.
    Many thanks!

  • @dawid_dahl
    @dawid_dahl Před 4 lety

    Please continue to show the process like you always do. It’s greatly appreciated!

  • @rishabhkalra9505
    @rishabhkalra9505 Před 5 lety +1

    This was actually pretty cool. I liked the whole idea to make seamless animations with this api. I always used to think making animations like this from scratch means a lot of css. This is a lot easier. Thanks for such great demo. Your channel is the only channel i follow for front-end tips and tricks. Keep up the good work :)

  • @peternicholson26
    @peternicholson26 Před 4 lety

    Thanks very much for this. I am at the start of a project at work that I have just used this technique on. Great timing! Legend

  • @SelenaFreeJack
    @SelenaFreeJack Před 4 lety

    I love you man. One of the best youtubers. I've been looking for something like this for the past 10 hours.

  • @poooooow
    @poooooow Před 5 lety +1

    Big thx.
    You helped me a lot improving my work and projects.

  • @shortsExperiment_
    @shortsExperiment_ Před 5 lety +1

    Awesome!!! I was looking for an easy way to do scroll animation without any third party scripts, and then your video appeared.....

  • @dafimperator
    @dafimperator Před 5 lety

    I love the way you teach, thanks as hell!

  • @siddhartharoy5263
    @siddhartharoy5263 Před 5 lety

    Yoooh, Awesome vid !

  • @kashif_i
    @kashif_i Před 5 lety +2

    Thanks for explanation! Very useful.

  • @Dev_UI
    @Dev_UI Před 5 lety

    that's new for me! thanks for the tutz man!

  • @Adanmacreates
    @Adanmacreates Před 4 lety +1

    You are saving my senior coding project because sadly my university has failed me lmao.

  • @asithanilanga6797
    @asithanilanga6797 Před 3 lety

    You are the best!! Finally found it haha! Thank you so very much!!

  • @I.G.G.G.
    @I.G.G.G. Před 4 lety

    Your videos are so helpful man.

  • @angierodriguez5830
    @angierodriguez5830 Před 4 lety +1

    Finally a tutorial that explains things well and I actually learn something. Tons of tutorials on CZcams that just tell you what to write and don't explain anything. Some people just don't know how to teach but Gary, thank God, is not one of those.

  • @MrAndi1281
    @MrAndi1281 Před 3 lety

    such a great tutorial!! thanks soo much

  • @FullStackMaster
    @FullStackMaster Před 5 lety

    Great tips nice and clean!

  • @DiegoMilian117
    @DiegoMilian117 Před 4 lety

    Thanks man! You're the best.

  • @rodrigonoales
    @rodrigonoales Před 4 lety

    Thank you for such a great tutorial...

  • @tune_into_gaming
    @tune_into_gaming Před 3 lety

    clear explanation it worked on my website thanks man.....

  • @snakone
    @snakone Před 5 lety

    thanks for the tutorial, i was looking for something like this. I have a menu with (swipeRight) event on the whole page and a Carousel at the bottom aswell. Carousel has it's own swipe events overlaping with the menu swipe, sometimes when you wanted to swipeRight on the Carousel, the menu goes instead. Now i can disable the menu (swipe) while I'm on the Carousel section :)

  • @Almighty_Flat_Earth
    @Almighty_Flat_Earth Před 5 lety +14

    Do some use case videos about MutationObserver and ResizeObserver.

  • @anawhite2562
    @anawhite2562 Před 4 lety

    I don't know about you but I just love vanilla JS. Feels real for some reason. Why is that I wonder. Thanks so much for this video!

  • @jeffreybriceno
    @jeffreybriceno Před 5 lety

    Pretty cool video.

  • @maksymyankivskyy2419
    @maksymyankivskyy2419 Před 5 lety

    Awsome !

  • @hassantariq8847
    @hassantariq8847 Před 5 lety

    Thank you 💎👌🏻

  • @maxtaylor3531
    @maxtaylor3531 Před 5 lety

    This is freaky. I was literally just learning about this earlier today and you just posted a video about it!

  • @prakashale1627
    @prakashale1627 Před 5 lety

    Nice!

  • @davidsaso1234
    @davidsaso1234 Před 4 lety +1

    Two problems; when you scroll away from the element which is being animated, it resets inmediatly and it plays the animation from the beginning once you scroll back to it. I'd like for it to do the animation backwards as soon as you scroll away form it, so that if you scroll back, you can see it going back to its original state as if it was undoing the animation.
    The second problem is that, let's say you have two sections of 100vh, if an element from section two is moved into section one because you wanted to slide in from the top (transform: translateY(100vh)) BUT at the same time is hidden from section one because overflow in section two has been set to hidden, the browser will treat it as being in the viewport because it has been moved into section one the whole time so it won't trigger the animation.

  • @seanknowles4769
    @seanknowles4769 Před 4 lety

    What we really need is a fullstack course covering Sapper SSR/Svelte with all the bells all whistles

  • @prabhkang226
    @prabhkang226 Před 3 lety

    You just solved one of the biggest hurdle of making basic landing pages

  • @SunnyVakil
    @SunnyVakil Před 5 lety +4

    Hi Garry, Can you make one tutorial video on How to make Web components with Vanilla JS? this video is really great.

  • @annasognosia
    @annasognosia Před rokem

    thank you

  • @ck0024
    @ck0024 Před 3 lety

    Now I will make my own *AOS*

  • @rinatvaliullov3247
    @rinatvaliullov3247 Před 5 lety

    Very cool! And we don't need any external library even

  • @johnjohnson4484
    @johnjohnson4484 Před 4 lety

    hey this is Gary "im not making this responsive" Simon with coursetro

  • @swartex92
    @swartex92 Před 4 lety

    cool!

  • @arthurshaidullin7981
    @arthurshaidullin7981 Před 4 lety

    thanks )

  • @jamesthaoulin3955
    @jamesthaoulin3955 Před 5 lety

    Thanks for your tutorial Gary. Very informative I'de like to use this API using a smooth scrolling container but for a reason i ignore, entry are not targeted. When i remove my smooth scroll container, everything is running fine thoe. Any idea why this happen? Thanks

  • @luchogonzalez6431
    @luchogonzalez6431 Před 4 lety

    love u

  • @HamzaKhan-qm5bl
    @HamzaKhan-qm5bl Před 5 lety +1

    Can we call a function inside intersection observer?i have been trying to do that but it doesn't work

  • @matheusrodrigues-gk2os
    @matheusrodrigues-gk2os Před 5 lety +1

    Someone can help me please ???
    I was using this tutorial, and i would to set the follow keyframe to my divs to move down to up :
    @keyframes anim1 {
    from {
    transform: translateY(100px);
    opacity: 0;
    }
    to {
    transform: translateY(0);
    opacity: 1;
    }
    }
    However, before the keyframe starts the divs start move down to up without stop ! Only after when i scroll more them, the keyframe occurs normal.

  • @rockyd3v807
    @rockyd3v807 Před 3 lety

    The word "forwards" in the animation seems to be giving me issues with the modals on my page, the background drop down of the modal is now on the top layer and modal does not behave normally, could some one lend me a hand? modal was created with bs4

  • @bigfoot131
    @bigfoot131 Před 5 lety

    You make this stuff look so easy. can u be so kind as to show how we can implement this in react?

  • @cwinter90
    @cwinter90 Před 5 lety

    We actually use this to start/stop/reset playing of rotating videos

  • @johnniegilkerson4724
    @johnniegilkerson4724 Před 5 lety

    I installed the live scss compiler but cant get it to show at the bottom.

  • @prakashale1627
    @prakashale1627 Před 5 lety

    can you please do more videos on svg animation?

  • @lcho9871
    @lcho9871 Před 3 lety

    In light of ease, how about a tutorial on using this technique to implement a simple virtual horizontal scroll on, let say a html table or items ? Thank you.

  • @priyanshsharma9313
    @priyanshsharma9313 Před rokem

    I loved your tshirt more than the animation man, Love Metallica

  • @pixiedust6630
    @pixiedust6630 Před 5 lety +3

    I don't know why I always read ur name as "DesignIntercourse" at first glance.
    I then have to look again and correct myself lmao

  • @luismelo4131
    @luismelo4131 Před 5 lety

    can you do a tutorial of this api in vue cli?

  • @chefbennyj
    @chefbennyj Před 4 lety

    Edge browser is faster by applying styles but all the other browsers seem to do better applying classes with transition properties.

  • @igoroliveira9146
    @igoroliveira9146 Před 4 lety

    Hello, What is the song at the beginning? :)

  • @Bangalipula
    @Bangalipula Před 5 lety

    What about loading animation only for the first time? Like when I scroll back to top and scroll down again the animation won't show.

    • @manugalaxy14
      @manugalaxy14 Před 4 lety +1

      Just delete the else part from this video.

  • @mahsamrz5787
    @mahsamrz5787 Před 3 lety

    Hi there How can i make this happen with Barba.js too?

  • @robingergelyfi4829
    @robingergelyfi4829 Před 4 lety

    Anyone knows why I got tihs? :
    Uncaught TypeError: Failed to execute 'observe' on 'IntersectionObserver': parameter 1 is not of type 'Element'.
    at main.js:15
    Therefore its not working for me and I have no idea whats wrong.
    Thanks!

    • @chengjieyun59
      @chengjieyun59 Před 4 lety

      You forgot to change `observer.observe(images);` to
      `images.forEach(image => {
      observer.observe(image);
      });`

  • @preet8457
    @preet8457 Před 5 lety

    if you want to add more than one animation on different classes, how can we do that? In simple words how can we add 2 or more than 2 different animations on a single web page?

    • @peternicholson26
      @peternicholson26 Před 4 lety

      This is exactly what I was about to ask. It would be good to see how to change the javascript code to allow for multiple animations

    • @preet8457
      @preet8457 Před 4 lety

      @@peternicholson26, i got it. you have to change only two things. let me explain.
      in the very first line -
      const ( Change this ) = document.querySelectorAll('.classname');
      in one of the last lines -
      (change this).forEach(image => {
      observer.observe(image)
      okay so change the words which I have written as (change this) to any other name. And set a new class and animation. that's it.

  • @vincesanchez7790
    @vincesanchez7790 Před 4 lety

    does IntersectionObserver is async in action???

  • @andonir.6320
    @andonir.6320 Před 3 lety

    Is that the Yngwie guitar?

  • @chrizzzly_hh
    @chrizzzly_hh Před 5 lety

    Nice tutorial, but not the best practise to include variables (delay) without a fallback if the data-delay isn't supplied!
    nevertheless - keep it up!

    • @anawhite2562
      @anawhite2562 Před 4 lety

      Any pointers on how to implement a fallback would be very much appreciated.

  • @lefxxwill7740
    @lefxxwill7740 Před rokem

    I thought absolutely positioned elements don't respect margins.. ?

  • @doubleyousl3726
    @doubleyousl3726 Před 3 lety

    15:20

  • @SebastianPerezG
    @SebastianPerezG Před 5 lety

    Maybe I will change the height :100vh for min-height:100vh ..

  • @bombayblur3797
    @bombayblur3797 Před 5 lety

    I didnt see any pure CSS courses on coursetro.

    • @DesignCourse
      @DesignCourse  Před 5 lety

      I have a frontend developer's course (2019) that teaches HTML and CSS for beginners. Other than that, there's a bunch of niche tutorials on css.

  • @Jennifer-ju8de
    @Jennifer-ju8de Před 3 lety

    EUHM

  • @user-ri8ow3qh7l
    @user-ri8ow3qh7l Před 4 lety

    align-items, not place-items.

  • @anzefajfar3072
    @anzefajfar3072 Před 4 lety

    Great, but not really practical, since the support is sub 90%...