Learn free online HTML5, javascript, and jquery Tutorials by Examples

Saturday, 2 February 2019

jQuery, JavaScript, HTML: how to load images after everything else is loaded?

window.addEventListener('load', function(){
  //For img src
var allimages= document.getElementsByTagName('img'); for(var i=0; i<allimages.length; i++) { if (allimages[i].getAttribute('data-src')) { allimages[i].setAttribute('src', allimages[i].getAttribute('data-src')); allimages[i].setAttribute('data-src', '') } }         //For Background image var alldivs= document.getElementsByTagName('div'); for(var i=0; i<alldivs.length; i++) { if (alldivs[i].getAttribute('data-src')) { alldivs[i].style.backgroundImage = "url('" + alldivs[i].getAttribute('data-src') +   "')"; alldivs[i].setAttribute('data-src', '');} }}, false);

No comments:

Post a Comment