10 examples of 'preload img jquery' in JavaScript

Every line of 'preload img jquery' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
30export function preloadImg(src, success, error) {
31 const img = new Image();
32
33 img.onload = function () {
34 success(img);
35 };
36
37 img.onerror = function () {
38 error(img);
39 };
40
41 img.src = src;
42}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

41function preloadImg(src, success, error) {
42 var img = new Image();
43
44 img.onload = function () {
45 success(img);
46 };
47
48 img.onerror = function () {
49 error(img);
50 };
51
52 img.src = src;
53}
79function preloadImg(image) {
80 var img = new Image();
81 img.src = image;
82}
125export function preloadImage(url, onload) {
126 const image = new Image();
127 image.src = url;
128 image.onload = onload;
129 return image;
130}
41function preload() {
42 for(var i = 0; i < imagesArray.length; i++) {
43 if(imagesArray[i].hasAttribute('preload') && imagesArray[i].hasAttribute('minimal-lightbox')) {
44 var createImage = new Image();
45 if(imagesArray[i].getAttribute('minimal-lightbox') != '') {
46 createImage.src = imagesArray[i].getAttribute('minimal-lightbox');
47 }
48 }
49 }
50}
46function preload(src) {
47 if (src in preloads)
48 return;
49 preloads[src] = new Image();
50 preloads[src].src = src;
51}
54function loadImg(src, callback) {
55 var img = new Image();
56 img.src = src;
57 img.onload = function(event) {
58 loadImg.loaded++;
59 callback && callback(event);
60 };
61 return img;
62}
20loadImage(url, key) {
21 return new Promise((resolve) => {
22 const img = new Image();
23 img.src = url;
24 img.onload = () => {
25 resolve({
26 [key]: img
27 });
28 }
29 });
30}
25function preloadImage(path, callback) {
26 const image = new Image();
27
28 image.onload = function() {
29 callback(image);
30 };
31
32 image.src = path; ///
33}
7function preloadImgSimple(url,afterwards) {
8 var img = new Image();
9 img.src = url;
10 if(img.complete) {
11 afterwards();
12 }
13 else {
14 img.onload = function() {
15 afterwards();
16 };
17 }
18}

Related snippets