Created
October 13, 2020 03:58
-
-
Save bacoords/c52476b80edd5c34770cc4d768410f8a to your computer and use it in GitHub Desktop.
public - function to load large images
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Function to background load images and swap out their source. | |
function replaceImageSrc() { | |
jQuery('svg image').each(function(){ | |
var el = jQuery(this); | |
// Get the new href. | |
var href = el.attr('xlink:href'); | |
href = href.replace( 'assets_small', 'assets_large' ); | |
href = href.replace( '-s.', '-l.' ); | |
// Create an image. | |
var curImg = new Image(); | |
curImg.src = href; | |
curImg.onload = function(){ | |
// do whatever here, add it to the background, append the image ect. | |
// imgHolder.appendChild(curImg); | |
el.attr( 'xlink:href', href ); | |
console.log( href ); | |
} | |
}); | |
} | |
document.addEventListener('DOMContentLoaded', replaceImageSrc ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment