0

Hi i am having black and white images on my website on mouse hover need to change the image immediately.But it is taking time to change the image for the first time later on it is changing the images immediately.

Code:

 <div id="content">
    <img src="<?php echo base_url();?>theme/images/expertise/1.png" class="images1" onmouseover="this.src='<?php echo base_url();?>theme/images/1.png'" onmouseout="this.src='<?php echo base_url();?>theme/images/expertise/1.png'" />
    <img src="<?php echo base_url();?>theme/images/expertise/2.png" class="images2" onmouseover="this.src='<?php echo base_url();?>theme/images/2.png'" onmouseout="this.src='<?php echo base_url();?>theme/images/expertise/2.png'"/>
</div>

Css

#content {
  margin-top: 21px;
  margin-bottom: 57px;
 }
.images1,.images2 {
    display: inline-block;
    vertical-align: middle;
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    box-shadow: 0 0 1px rgba(0, 0, 0, 0);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    -moz-osx-font-smoothing: grayscale;
    -webkit-transition-duration: 0.3s;
    transition-duration: 0.3s;
    -webkit-transition-property: transform;
    transition-property: transform;
 }
 .images1:hover,
 .images1:focus,
 .images1:active,
 .images2:hover,
 .images2:focus,
 .images2:active
  {
    -webkit-transform: scale(1.1);
     transform: scale(1.1);
   }
user8001297
  • 173
  • 1
  • 4
  • 18

3 Answers3

0

The easiest way is to create an image holding both pictures in one file. then you use a div with the desired size and the image as background.

you define the position so, that the first picture is visible and the other not.

if you hover, you change the position, so the other picture gets shown.

Here is a relatively similar question: CSS hover image position change

Community
  • 1
  • 1
helle
  • 11,183
  • 9
  • 56
  • 83
0

You will have to adjust the URL's, but let me know if this works for you.

.images1,.images2 {
    display: block;
    vertical-align: middle;
    box-shadow: 0 0 1px rgba(0, 0, 0, 0);
    transition: transform .3s ease;
    will-change: transform;
    margin-bottom: 20px;
 }
 .images1:hover,
 .images1:focus,
 .images1:active,
 .images2:hover,
 .images2:focus,
 .images2:active
  {
     transform: scale(1.1);
  }
<div id="content">
    <img src="http://placehold.it/350x100/ffffff" class="images1" onmouseover="this.src='http://placehold.it/350x100/003500'" onmouseout="this.src='http://placehold.it/350x100/ffffff'" />
    <img src="http://placehold.it/350x100/ffffff" class="images2" onmouseover="this.src='http://placehold.it/350x100/003500'" onmouseout="this.src='http://placehold.it/350x100/ffffff'"/>
</div>
Gerard
  • 15,418
  • 5
  • 30
  • 52
0

Added the preloader script in header.php file it worked

<script type="text/javascript">
 function preload(arrayOfImages) {
var ImageContainer ="<div style='display:none;'>";
$(arrayOfImages).each(function(){
 ImageContainer += "<img src='"+this+"''>";
});

ImageContainer +="</div>";
$(".ourexpertise").append(ImageContainer);

}
// Usage:
var arrayOfImages =[
'http://www.example.com/theme/images/1.png',
'http://www.example.com/theme/images/2.png',
'http://www.example.com/theme/images/3.png'
 ];
 $(document).ready(function(){
preload(arrayOfImages);
});
</script>
user8001297
  • 173
  • 1
  • 4
  • 18