Learn Resize Observer In 5 Minutes

แชร์
ฝัง
  • เผยแพร่เมื่อ 4 ต.ค. 2024

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

  • @UmarAlFarooq
    @UmarAlFarooq 2 ปีที่แล้ว +101

    What I LOVE about your videos:
    1. You jump right into the topic. No wasting time.
    2. No sponsor or ads
    3. You don't keep telling your viewers to "like and subscribe" which wastes MORE time multiplied by the number of viewers
    4. Each second of your video is important. You don't have any pauses, non-content or even lame jokes.
    5. Audio, video and production quality is top notch.
    6. Your content is innovative, cutting edge and extremely helpful!
    YOU sir, deserve a Nobel prize instead of most of the jokers who usually get it. I hope all other content creators learn these things from you. I hope that all viewers also take notes and comment in other videos to be more like you.

    • @patriciaverso
      @patriciaverso 2 ปีที่แล้ว +11

      I'm gonna offer a different perspective, because most people fail to realize how TH-cam works.
      1. No comments here
      2. Some people work using TH-cam. Their income comes from their videos and TH-cam's ad revenue is negligible for small channels.
      3. TH-cam themselves instructs creators to "call to action", and therefore rely on this metric to promote the video, which in turn gives more views and more ad revenue for TH-cam of course, but also for the channel. So it's a waste of time for you personally, but for the creator it's a necessary measure to stay relevant (also, what the hell do you mean be "multiplied by the number of users"? We don't have a collective maximum of time we all share. There's no more time wasted per person, what the hell?)
      4, 5 and 6. No comments here.
      Closing comments: you claim others are "jokers" because they don't make the styles of videos you like. It's okay to dislike. There's even a button for doing that. It's NOT okay to bash on those just because you don't like that.
      So in a nutshell, you frame your compliments to Kyle by critiquing others in a narrow minded way which not only doesn't help anyone, but is also really rude. For the sake of others, please refrain from looking at people as objects of your entertainment and start looking at them as individuals, which they are.

    • @UmarAlFarooq
      @UmarAlFarooq 2 ปีที่แล้ว +7

      @@patriciaverso the number of seconds you waste in the video is multiplied by the number of viewers. If you waste 5 seconds and a million viewers watch your video, you've effectively wasted 2 months of humanity's time.
      If everyone is "calling to action" it becomes a cheap trend rather than something essential. Try this experiment. Have videos with the same content in two different channels, with the only difference being that in one you pester the viewers to "like, subscribe, alert". See which channel gets more viewers.
      What's insulting and rude is treating viewers like children or senile people who need to be reminded constantly. There's not a single regular viewer who doesn't understand the "like" button or the subscribe. If you sum up all the videos that constantly badger people with this time wasting exercise every day across TH-cam, that's billions of hours, essentially killing the equivalent of 10 human beings who'd live to be a hundred.
      What I refer to as jokers are people like Yitzhak Rabbin and Yasser Arafat and Obama getting Nobel prizes. The "Drone President" who took the 2 wars he inherited and turned them into 7 wars gets a peace prize.

  • @TheRealCAPerry
    @TheRealCAPerry 2 ปีที่แล้ว +78

    It'll be interesting to see how this technique compares with Container Queries once they become available.

  • @adebiyial
    @adebiyial 2 ปีที่แล้ว +172

    I don't think mentioning media queries in this context works, at least for me. Resize observer and media query are fundamentally two different things and work differently. In fact, if a media query can do it, I'd take that first. Anyway, nice and concise video - thank you.

    • @JNeathawk
      @JNeathawk 2 ปีที่แล้ว +5

      agreed. a CSS solution is almost always better than a similar JS solution. Only time I would pick JS over CSS is if it absolutely needs to do or look the exact way it does in JS and I can't achieve it with CSS. I am never surprised at how much JS can slow things down when it's used willy nilly.

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

      Can be vary useful when adding attributes to an element via JavaScript if the width reaches a certain point.

    • @ArvanisPL
      @ArvanisPL 2 ปีที่แล้ว +3

      ​@@JNeathawk Totally agree. Maybe you won't notice it on a simple static website, but doing stuff in js when you can easily handle it in css is a performance killer.

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

      My thoughts exactly! The thumbnail and first minute of the video made me think, "is this guy really going to use an observer in place of a media query for the page?" Still, I'm glad to have learned about this as I've never messed with it in 5 years. I've used the more complicated mutation observer, and admittedly, my naivety would have made me write longer JS to do the same thing.

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

      Well, there are times where you'll actually need to make a component responsive, say you have the same component on two different page, in page 1 it takes the full screen width, but in page 2, it takes half the page, it'll be much better to make such component responsive based on the width and height of that component instead of the width and height of the screen.

  • @billyfairbank
    @billyfairbank 2 ปีที่แล้ว +29

    Cleanest explanation of this I have seen. Been a dev for 15 years and learned a couple new things. Well done!

  • @Paninicus
    @Paninicus 2 ปีที่แล้ว +6

    Amazing how Kyle keeps bringing up JS/HTML features I haven't heard of (after being a web developer since 1996).

  • @djibrilm__-
    @djibrilm__- ปีที่แล้ว

    Everytime I watch your videos i get something new 🙂 thanks

  • @alvaroprietovideos
    @alvaroprietovideos 2 ปีที่แล้ว +39

    I have been using this technique extensively in some of my projects, specially in those where certain reusable components can be used in very different context, allowing them to fit into their containers smoothly. Each reusable component gets a special sizing class according to the available space (xxl, xl, and so on...). Resize Observer can be combined with Mutation Observer to increase reusability of componentes.

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

      How does it perform when multiple elements have the observer attached?

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

    Thank God this is in my recommended videos...I needed this so bad thanks Kyle.

  • @willemaw9992
    @willemaw9992 6 หลายเดือนก่อน

    You really save my life for this video.
    Thank you so much

  • @toddribnek6660
    @toddribnek6660 2 ปีที่แล้ว +3

    Dude, nice. Glad to hear the performance is good with this approach.

  • @j-lewis
    @j-lewis ปีที่แล้ว

    You're da MAN, thanks for such a good video! Clear & fix info in here!

  • @LePhenixGD
    @LePhenixGD 5 หลายเดือนก่อน

    This technique is incredibly handy, especially in scenarios where you need to dynamically adjust the dimensions of an HTML canvas based on changes in the height of a parent element, it's a lifesaver

  • @Dcooper676
    @Dcooper676 2 ปีที่แล้ว +9

    Hi Kyle thanks for this outstanding video!!, waiting for ur e-commerce website tutorial😀

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

    Understood this concept only after watching this video. Thanks!

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

    That's why we are waiting for Container Queries, can't wait to see it in action!

  • @RodrigoMendoza7
    @RodrigoMendoza7 2 ปีที่แล้ว +57

    This is what the upcoming Container Queries in CSS are for, right? So as to accomplish the same but avoiding using JS.

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

      Yes.

    • @DevTeacher
      @DevTeacher 2 ปีที่แล้ว +3

      Yea, it will be pure CSS and full power.

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

      Exactly.

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

      Pure CSS will be the way to go for this for the majority of use cases. This implementation (while handy, always happy to have another tool) feels bloated to me given what it accomplishes.

    • @dave6012
      @dave6012 2 ปีที่แล้ว +3

      Just gotta wait 4 years for full cross-browser compatibility.

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

    Something's it feels like your videos are just for me. Like the Intersection Observer video I used to to build a scroll spy, then this I need something to show mobile and desktop preview and this is the solution.

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

    Wow! Thanks Kyle! Will try that out as soon as tomorrow ;)

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

    thank you now we have container queries

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

    This is a banger Kyle🔥 thanks man for this awesome info🙌🏼

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

    Good video. I like how you focus on one concept and leave other details out for the viewer to learn more about if they need to. Keep it up!

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

    Cool technique! I have been using CSS all the time until I saw your video :D

  • @ינוןאלבז-כ1ז
    @ינוןאלבז-כ1ז 2 ปีที่แล้ว

    Your channel is the best dev channel on youtube

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

    Hey Kyle, in your each video I am learning something new. Thanks a lot and please keep sharing such a knowledge in future as well 😊

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

    I can't tell you how subscribed I am to this channel.

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

    Thank you, Kyle, many of your videos helped me a lot, this was as always excellent.

  • @8koi245
    @8koi245 2 ปีที่แล้ว

    Bruh I just needed this 2 days ago, Pog

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

    Amazing video! Thank you Kyle and have an amazing new year!

  • @ХайёмОдинаев-ж3х
    @ХайёмОдинаев-ж3х 2 ปีที่แล้ว

    Thank you, for still showing something new I didn't know

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

    I really hate media queries so this video makes me happy

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

    One of my Favorite TH-camr ! Thank you for sharing your knowledge!😊✌️

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

    Thanks Kyle!

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

    thank you so much for your work!

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

    Really cool video! 👏👏👏

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

    Gonna use this in my upcoming projects am sure

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

    I didn't know about these. Thanks.

  • @bobdinitto
    @bobdinitto 2 ปีที่แล้ว +5

    Wow! This is amazingly powerful since you can customize the sensitivity of the scene by modifying the granularity of the observable object network, since it's fully programmable. I'm not used to being able to do stuff like this with HTML. Thanks for the succinct explanation.

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

    Thanks, very helpful

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

    Nice. Can’t wait to use this.

  • @estebanfelipe3980
    @estebanfelipe3980 7 หลายเดือนก่อน

    You are the besttt! 🙌

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

    Very cool. I don't know right know the benefit... But I never know... Thanks

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

    Very informative - thank you so much!

  • @robertzeurunkl8401
    @robertzeurunkl8401 2 ปีที่แล้ว +3

    Last time I used contenteditable, I ran into snags right away. Sure, you can edit the text in a contexteditable div. But my users had other plans. They thought they could cut and paste text from other web pages into my contenteditable div. And they could. But what you don't see when doing that is that if you cut text from a webpage, and paste it into a CE div, it cuts and pastes not just the text but in fact ALL of the HTML that they highlighted when selecting that text. I ended up with html tags inside my CE div, which, of course do not show up (they're html tags), but the *effect* of them was felt immediately. So, heads-up about CE elements.

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

    Thx Web Dev, good content

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

    Um dos melhores canais de trickster js do mundo.

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

    Thank you again for the knowledge you are sharing

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

    Well explained! Big fan. Thx Kyle

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

    Great!! Thank you kyle

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

    You make the web simplified!!

  • @a-ezzat5677
    @a-ezzat5677 ปีที่แล้ว

    you are my hero , i like the subjects you raised , if you explain a few about code written in complex scenarios, e.g."this code is to do bla bla , it's written here because bla bla" it would be more awesome in general not for that video, greetings from Egypt

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

    Awesome video. Would be great if you make a video about how to use it with React.

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

    This is cool, thanks for sharing !!

  • @leaxem
    @leaxem 2 ปีที่แล้ว +6

    Great video as always Kyle. Please do one for MutationObserver.

    • @WebDevSimplified
      @WebDevSimplified  2 ปีที่แล้ว +9

      I already have that video recorded and it should release in a week or so.

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

      @@WebDevSimplified You are the best bro.

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

    Pretty cool video ❤

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

    I can't thank you enough, Kyle

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

    You are awesome and the guitar behind you is fantastic btw can you play heavy metalcore riff

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

    Awesome sir

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

    very helpful thx

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

    It depends on the use case. If you have to adapt to exact size, or change of overflow state (to sync width between two zones), then ResizeObserver is the way to go.
    If you’re adapting to size *zones* to change certain settings, then container queries.

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

    Great little tool. Could add a whole new functionality to a website.

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

    Academy Award for Best Hair on a TH-cam Dev Channel 2020

  • @baolee4622
    @baolee4622 2 ปีที่แล้ว +6

    This is awesome. It would be perfect if you can show us in React.

  • @rick.d
    @rick.d 2 ปีที่แล้ว +28

    So this demo shows a single element with a Class - can you address what would happen both functionally and especially performance-wise with a BUNCH of elements with the same class? Is there a point at 10 or 100 or 1000 elements where the array gets out of control, making using that class selector just count-productive? And thanks for these vids!

    • @genechristiansomoza4931
      @genechristiansomoza4931 2 ปีที่แล้ว +3

      You can find it out and share with us if you will.

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

      I’m not familiar with Resize Observer, but as far as I can tell, performance wise would be on par with any other build it method. Time complexity would end up being O(n) if you plan to evaluate each one of them

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

      btw currently here it only selects the first ".box" element in the entire dom.

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

      The next problem is ordering of the array, trying to manage more and more elements will get hairy very fast. A pure CSS solution should be employed for something small like this once that functionality is released.

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

    Thanks Kyle

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

    Wow, this is great!

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

    Having to resort to Javascript to control your ui is a code smell...it better be really intentional and meaningful!

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

    So this is how you make the polyfill for the upcoming css container queries

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

    It's interesting. But what about the performance if used so many element checks?

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

    awesome !

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

    Thank u😍

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

    Awesome. 👏👏👏

  • @maximprosv
    @maximprosv 2 ปีที่แล้ว +9

    Hello, thanks for the video. Unfortunately the point that resize observer is more performant than media queries is wrong. At the end of the day css is handled by browser itself and js is high level api. The rule of thumb is - do everything with css and in cases css cant help - use js. Thanks.

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

      I never mentioned that it is more performant than media queries. I said that resize observer is pretty performant, but that is in comparison to doing things based window resize events which can really cause performance issues.
      It is always best to use CSS when possible, but this is not possible with media queries.

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

      @Katappa hu jo bahubhali ko mar diya toh tum kon ho learn more in JavaScript itself. Things like arrays and its methods(higher order functions), objects and its methods, asynchronous JavaScript (promises, async/await), and much more.

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

      @Katappa hu jo bahubhali ko mar diya toh tum kon ho here check him to learn JavaScript.
      th-cam.com/video/EfAl9bwzVZk/w-d-xo.html

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

    CSS @container can now do the job mostly.

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

    Yeah you are the best one

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

    I think use media query is the best for development and team, but observer is the best for who are creative person

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

    love this!

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

    VERY NICE!

  • @Vlad-em1bx
    @Vlad-em1bx 2 ปีที่แล้ว

    Nice!

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

    Hey Kyle. Thanks.

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

    superb

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

    Does this affect performance when used extensively?

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

    Will we able to do something similar with container queries (if they become supported) ?

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

    One gotcha I ran into with Resize Observer, is that it doesn't fire for display:inline elements when you resize the window and the height/width changes due to the number of lines of text changing.

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

    Can't wait for wider adoption of container queries

  • @ДмитрийГлушко-р8ж
    @ДмитрийГлушко-р8ж 2 ปีที่แล้ว +1

    Good video, but I wish you had showed the CSS file.

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

    Please make video on dynamic font size in javascript.

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

    Yahoooooo!!!!

  • @ericzorn3735
    @ericzorn3735 2 ปีที่แล้ว +3

    Hey Kyle, isn’t this what container queries are going to be?

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

    This video is good. Hopefully there has a tutorial on react theme with custom hook and styled components. 😁

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

    Container queries in css can do it natively. But they not supported by every browser yet

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

    Good to know this is around but it’s hard to figure a practical use case for this in production.

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

    Could you show us how to keep the height of columns in a flex container regardless the number of lines of text in them? Thanks

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

    awesome

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

    One big issue is the browser support of resize observers and other javascript observers. If you're doing this on a production code, you might have a problem with visitors making use of older browsers.

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

      You are right, compatibility should be considered. But new and powerful api is more exciting. And they will be implemented wisely.

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

      Depends on what you need to support, and how many versions back you need to go. Even for production, you might be able to get away with using a new feature & just poly-filling older browsers. A quick look online & there's an NPM polyfill for resize observer that supports IE9.

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

    So what next observer video Will u make? I hope MutationObserver

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

    wow... nice hair style :) and nice video :)

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

    This was epic

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

    Interesting

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

    hi there! thanks for the tutorial I wanted to know which screen recorder do you use! thanks in advance!

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

      Most likely OBS (Open Broadcaster Software), most streamers use it, you can use it to stream or record, very powerful and free.

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

    Great video. How do you manage the performance with a defer?