Analyze_
Posted on December 12, 2023
I figured out a way to preload images in html and css. I have used this for stuff like buttons that have multiple different images (for when it is clicked vs not being clicked). A lot of the time, you will click on the button then it will take a second to load the background.
How to do it:
In your html, create a
with the class of hidden.Put img tags with the srcs of all of the images you want to load within that .
For example:
<div class="hidden">
<img src="images/open_button_click.jpg" alt="">
</div>
The CSS:
Paste this into your CSS:
.hidden {
position:fixed;
bottom:0px;
left:0px;
pointer-events: none;
opacity:0%;
}
What this does is hide the elements visually then makes it so they don't affect anything else on your page.
That's all I wanted to keep this simple.
💖 💪 🙅 🚩
Analyze_
Posted on December 12, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
webdev 7. How to Embed Images and Videos in HTML: A Beginner’s Guide to Enriching Your Web Pages
September 7, 2024