1. DOM content
a. Event I like to go over is the load event and it's actually similar to dog content loaded. The difference is the load event does wait for things like external stylesheets or images to actually be parsed and loaded and ready to go before firing. Now it is a subtle difference and usually you're probably just going to want to use DOM content loaded. You know most use cases this will do just fine please check here our list of digital marketing companies in madhapur updated. If you did want to do something with for example an external stylesheet or an image though probably want to use load instead.
b. So those rare cases where you might want to do so just to go over what that would look like so let's say we do have an image we'll put it in our log div. So we'll do an image tag give it an ID. We'll call it my image and we give it a source. And I've actually just grabbed this image and uploaded it to image her. And the second list of digital marketing companies in madhapur Now this might not work or it might if the image is cached the image is not cached we should see the height being and the width being zero. Let's try it out.
c. If we try to do it in our dorm content loaded. So let's do Konst my image equals document or get element by id and let's see the ID is my image. And this just consulate's some info out about this image so we can say height plus my image offset height. It's how you do that. Plus space plus width plus my image start off set with right. Let's see if it tells us anything about this image. Once the DOM content is loaded.
a. So let's try to open up our console let's refresh it and it says height zero with zero. Even though we can see that we have some adorable puppies here. Right. So obviously this image is a lot bigger than height zero with zero because the image had not loaded at the time we invoked this function. In other words the donkey and the loaded picked up.
b. It's all parsed ready to go. Let's go ahead and fire that event which is fine and it totally worked up to this point. Here we basically grabbed the image but it hadn't loaded it yet. And now if we try to refresh it probably will have those dimensions because it's been cached in the memory. Yeah we see the height and width now but only after the image has been cache by the browser. So let's say we don't want to worry about that we don't need to worry about caching or not we just always want to be able to get the height and here is our list of digital marketing company in india the width in which case we would want to do a load event listener and load event listeners or usually attach them to the window itself.
a. So window dart add event listener load and we can do check image size as the function name. For example so function check image size and we can just move this logic out cut pasted in here and now it should work as expected every time because this will not fire until everything is fully loaded and ready to go. Right. This could be external stylesheets. If you have multiple images or you want to wait to check all your image sizes this is what you would want to do. So let's try that here. Tom content loaded and parsed and then we can always check the height and the width.
b. Now at this point if we wanted to do some kind of transformative action on our image we could do that now I wouldn't recommend doing it this way I would recommend just doing it this way. Or even better using a smaller image in the first place.
b. But if we want to do something like my image style Daut width and we can give it a width of for example if we give it you know pixels let's do like actually pixels and then to preserve the proportions with the image of style height equals auto. So let's do a refresh. See what that looks like.
d. In that case then of course if you have multiple images you would just kind of need to throw a loop in your checked image size and just for fun let's use my image dot style dot board or radius because percent fresh. Hey Pretty cool stuff.