OnMouseOver with Delay when swapping image

6

I'm using a onmouseover , but it's giving delay from 0.5 to 1 second to change the image, when I put it in my hosting.

 <li>
    <img src="images/clientes/1.png"onmouseover="this.src='images/clientes/a1.png'"onmouseout="this.src='images/clientes/1.png'"/>
</li>
    
asked by anonymous 25.11.2015 / 16:45

1 answer

4

Because the two images are hosted on a remote host, it is natural to have to wait for it to load.

In this case, you can perform a preload of the images, one way to do this is with JavaScript.

//liste no Array abaixo todas as imagens que deseja realizar o pré-carregamento.
var imagemURLs = [
  "images/clientes/1.png",
  "images/clientes/a1.png"
];

imagemURLs.forEach(function (imagemURL, indice) {
  new Image().src = imagemURL;
});
    
25.11.2015 / 16:56