Answers for "onload image javascript"

3

javascript on image load

window.onload = function () {

        var logo = document.getElementById('sologo');

        logo.onload = function () {
            alert ("The image has loaded!");		
        };

        setTimeout(function(){
            logo.src = 'https://edmullen.net/test/rc.jpg';         
        }, 5000);
    };
Posted by: Guest on March-20-2020
0

preload images javascript

let preloadedMaps = [];
    let preloadedWorkRoutes = [];
    console.log('asdasdasdas')
    function preloadImages(preloadedMaps, preloadedWorkRoutes){
      var maps = [`${workMapDesktop}`, `${workMapMobile}`, `${playMapDesktop}`, `${playMapMobile}`];
      var workRoutes = workRoutesDesktop.concat(workRoutesMobile);
      for(let i = 0; i < workRoutes.length; i++) {
        preloadedWorkRoutes[i] = new Image();
        preloadedWorkRoutes[i].src = workRoutes[i]
      }
      for(let i = 0; i < maps.length; i++) {
        preloadedMaps[i] = new Image();
        preloadedMaps[i].src = maps[i]
      }
    }        
    preloadImages(preloadedMaps, preloadedWorkRoutes);
Posted by: Guest on April-14-2020

Browse Popular Code Answers by Language