The "scroll" event in JavaScript | window.onscroll

แชร์
ฝัง
  • เผยแพร่เมื่อ 25 ส.ค. 2024
  • By making use of the "scroll" event in JavaScript, you are able to react to when the users of your web page scroll down or up. Learn more in this video tutorial.
    In this video I take you through the usage of the "scroll" event on the Window object. This allows us to listen for when the user scrolls up or down the page - we then implement a function that displays a message box when the user has reached the bottom of the page.
    Support me on Patreon:
    / dcode - with enough funding I plan to develop a website of some sort with a new developer experience!
    For your reference, check this out:
    developer.mozi...
    Follow me on Twitter @dcode!
    If this video helped you out and you'd like to see more, make sure to leave a like and subscribe to dcode!
    #dcode #javascript #webdev

ความคิดเห็น • 116

  • @ajminpradhan1112
    @ajminpradhan1112 4 ปีที่แล้ว +13

    The simplistic explanation I have ever seen. Please keep bringing more videos like this for us. Thanks dcode

  • @hyfytale9577
    @hyfytale9577 5 ปีที่แล้ว +8

    Thank you!! I was trying to figure out how to get the total height of the page when its scrollable and then I stumble upon your video! This made me progress so much!

    • @dcode-software
      @dcode-software  5 ปีที่แล้ว +2

      No problem at all! Glad it could help you 😁

  • @Paulina-sc1xd
    @Paulina-sc1xd 19 วันที่ผ่านมา

    thank you for this video. It was very helpful for me. Short and to the point, this is what I needed

  • @aryanyadav3926
    @aryanyadav3926 2 ปีที่แล้ว +1

    Thank you so much for this video. I was searching for answers on how to add active class to a link in navbar on scroll and was getting JQuery code everywhere. After watching this video I was able to do that in one shot.

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

    Thanks a lot. All your tutorials are neat, precise and useful. Congrats, sir

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

    When it comes to JavaScript, Dom is the guy. These tutorials are so gooddddddd. Thank you so much!!!!

  • @stratavis
    @stratavis 4 ปีที่แล้ว +2

    Thanks man!! your video helped me on my front-end test

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

    Thank you so much, first normal video on this topic!

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

    You have done it with very simple code .. great work sir ..thabks a lot

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

    Thank you friend, your video was very helpful, greetings from Hidalgo, Mexico

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

    Thank you! I needed to know how to detect the scroll and landed here :) second video I land on your channel today on differents topics

  • @estengrove3350
    @estengrove3350 6 ปีที่แล้ว +3

    Been looking for a simple and concise way to understand this as i'm most recently getting into events. Really helpful and clearly explained. I was able to create my own styling and animation by adding a class from the first parts of the code you explained. Much appreciated! Was pulling my hair out for a bit over this lol

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

    You are a real live saver... Thank you!

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

    Very informative video. Thank you! Its over many important things.

  • @johnsmith-oy9kx
    @johnsmith-oy9kx 6 ปีที่แล้ว +2

    Awesome ! I was looking for this, thanks a lot

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

    So ..good explanation :)

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

    You just saved me a day :-)

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

    Awesome explanation, Thank you

  • @YunusParvezKhan
    @YunusParvezKhan 4 ปีที่แล้ว +3

    Thank you very very muhhh... after very muchh struggling I found my perfect solution....

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

    Thank you, I wanted to start learning javascript scrolling affects and this really helps, great work!

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

    Thanks a lot for this

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

    lovely video.....nicely explained...neat example used..thanks

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

    Thank you.This was so usefull.Keep going.

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

    Thanks mate helped me a lot today! earned your subscription

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

    Very nice and helpful. Thank you

    • @dcode-software
      @dcode-software  5 ปีที่แล้ว +1

      No problem! Thanks

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

      @@dcode-software +1 subscriber from me

  • @oneminutereview1385
    @oneminutereview1385 6 ปีที่แล้ว +1

    You're a lifesaver man!

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

    спасибо большое, всё понятно разложил по полочкам.

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

    Nice explanation

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

    Very cool tutorial, exactly what i needed :)

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

    Good one

  • @movine2344
    @movine2344 6 ปีที่แล้ว +1

    I love your video man.Can you make tutorial pure js custom scrollbar?

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

    What should I do, If I want to check Before reaching the bottom of around 10px before reaching the bottom

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

    Thanks bro :)

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

    In germany we say: vallah das video is zu geil

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

    спасибо !! коротко и ясно ! помогли !

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

    thx for this mazing explain

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

    Thank you!

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

    GOOD VIDEO

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

    thank you your awesome!

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

    thanks, it helped a lot. :)

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

    thank you a lot sir
    you are amazing

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

    Thank u my hero.

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

    good job !

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

    Very helpfull, Thankyou very much...

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

    helped me alot

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

    Thanks alot sir

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

    did as shown, not a single instance of event fired while scrolling. testing in chrome 88

  • @UsmanAli-cb2we
    @UsmanAli-cb2we 3 ปีที่แล้ว

    Informative vedio

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

    JavaScript for Background change of box when scroll down

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

    How can i scroll to the id that id suppose to be center of the window... Could you please send me code for that using JavaScript

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

    its great video

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

    thank you so much

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

    how can I do this for a sidebar scrollbar instead of a window scrollbar?
    const scrolled = document.getElementById("nav_menu-2").scrollY doesnt do anything

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

    Super helpfull!!! but I have some uestions... what if I want to set that function to a spesific part of the scroll insted the bottom? pls!!

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

      My guess is you could divide the total possible scroll by whatever you want and then match it to that. IE:
      while [currently scrolled amount] < [possible scroll amount] / 2, do whatever

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

    tks u so much

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

    HI,BRO
    WHEN YOU ARE SCROLLING THAT ONE ...
    WHAT IS THAT 157 ?

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

    Hey, guys! He, y'all!
    My name is... DOM - Document Object Model

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

    My scroll event won't fire for anything. So frustrated!

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

    ironically am working on a task from udacity nano degree which has the same lorem ipsum quote written in

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

    Is there a way to stop the scroll event? I made a program where I run the scroll event only when a certain element is in view, if the element is not in view I don't need that event to keep running, but I can't seem to find a way to stop it.

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

    Thanks for the explanation! How can i make one that shows the alert at 50% of the scroll?

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

      Use an if statement.
      If ( scrollable === scrolled /2){
      Command
      }

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

    I wanted to make something where their would be 3 circle and each time you scroll circle 1 turns black when you scroll down more circle 2 turns black and on and on.

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

    Hello! How can I set the scroll left by using the normal scroll down?

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

    very good. ;)

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

    Is it possible scrollbar on for only using pointer event

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

    Hi Dom. I have a challenge and maybe you could help. I have an image which looks like a pc screen. Underneath this i want to have an that is scrollable. Using zindex block the scroll. Can you think of a way to capture the scroll and pass it down to the (beneath the image)

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

    Thanks for the video! I'm trying to create a parallax effect for an image element. So when the user scrolls down or up, the element transform:translate(0,1px); accordingly, whether it's going up or down. Do you know how to do that?

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

      I wish to do the same .. could you do it?except the fact I wish to scale the image

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

    Hey, how about navbar? show navbar if reach the 100vh of page? Sorry, I'm beginner. :)

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

    What font you use in the page ?

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

    What do you mean when you say the height of the entire document?

    • @dcode-software
      @dcode-software  5 ปีที่แล้ว

      Basically the entire content, all the text, images etc

  • @TariqKhan-yk9mg
    @TariqKhan-yk9mg 2 ปีที่แล้ว

    Great tutorial, how to make left column fixed and right column scrollable? check apple headphone landing page. Please make a video on this

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

    3:05 #kalnotes

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

    What theme is this, dcode

    • @dcode-software
      @dcode-software  3 ปีที่แล้ว +1

      Hey, it's Roboto Mono

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

      @@dcode-software =)) i thougth my comment not gonna get reply due to "2 year ago" video. Thanks

    • @dcode-software
      @dcode-software  3 ปีที่แล้ว

      All g mate

  • @user-bi8my2hu5i
    @user-bi8my2hu5i 5 หลายเดือนก่อน

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

    so

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

    You shouldn't use the scroll event this way.. Highly unrecommended.

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

    so what did this guy showed us ? waste of time

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

    Thank you!