JavaScript Image Loader
How do I make an javascript image loader?
What is a javascript image loader? How do you make a javascript image loader? This script and codes were developed by Pedro Tavares on 01 December 2022, Thursday.
JavaScript Image Loader - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>JavaScript Image Loader</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css"> <link rel='stylesheet prefetch' href='css/rwxpbb.css'> <link rel="stylesheet" href="css/style.css">
</head>
<body> <p>For usage code, see:<a href="https://codepen.io/dipscom/pen/yOpjBW" target="_blank"> This pen</a></p> <script src="js/index.js"></script>
</body>
</html>
JavaScript Image Loader - Script Codes CSS Codes
/* **************************************** */
/* Default CSS styles being imported from:
/* https://codepen.io/dipscom/pen/RWXPBB
/* **************************************** */
p { margin: 10px;
}
JavaScript Image Loader - Script Codes JS Codes
var ImageLoader = function(path, dbug) { "use strict"; if(dbug) console.log("[IMAGE_LOADER] Init"); // Total count of images to load var count = 0; this.load = function(parent, names, extension, className, id) { // Grab the html tag based on the string provided using its id or tag name var container = document.getElementById(parent) || document.querySelector(parent); // For each image name in the names array names.forEach( function(name) { // Append the image created into the html container tag given container.appendChild(createImage(name, extension, path, className, id)) }) }; function createImage(name, extension, path, className, id) { if(dbug) console.log("[IMAGE_LOADER] Image " + name); // Add one to the count of images loading count++; // Create the element tag var image = document.createElement("img"); // If a path was provided, use it image.src = (path ? path + name + extension : name + extension) // If an id name was provided, use it - Otherwise, use the original filename image.id = (id ? id : name); // If a class name was provided, use it if(className) image.className = className; image.onload = countReady; return image; } function countReady() { // Once loaded // Subtract one from the count of images loading count--; // When the count reaches zero if( count === 0 ) { // All images have loaded // Create the event to dispatch the news var event = document.createEvent('Event'); event.initEvent("IMAGES_LOADED", true, false); window.dispatchEvent(event); } }
};
Developer | Pedro Tavares |
Username | dipscom |
Uploaded | December 01, 2022 |
Rating | 3 |
Size | 3,171 Kb |
Views | 8,096 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Shooting Hoops | 6,731 Kb |
Mask Within Mask | 3,843 Kb |
GSAP - Animate SVG path with AttrPlugin | 2,074 Kb |
Responsive Animated Moving Things | 8,646 Kb |
SVG Grid Mask | 3,267 Kb |
Catch Me If You Can | 4,094 Kb |
MOMO BROS | 5,043 Kb |
GSAP - Responsive Corner Navigation | 3,210 Kb |
Buttons.js - Example | 3,730 Kb |
SVG Grid Mask - With Color effect | 3,666 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Canvas Background Effect | Sonick | 3,513 Kb |
Pure CSS Menu | Bronsrobin | 3,321 Kb |
Angular Sandbox | Alexgurrola | 1,616 Kb |
Rrremark.com Overlay Highlighter | Derickruiz | 4,438 Kb |
Canvas snow | Win7killer | 2,572 Kb |
Greyscale image with filter in CSS3 | NickyCDK | 1,562 Kb |
React Vote Component | Souporserious | 5,465 Kb |
Prototype Responsive Homepage | Heyitsolivia | 7,677 Kb |
Responsive Pricing Table | Jeremycaris | 2,690 Kb |
Price Comparison Table | Orrinward | 3,459 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!