toggle image on hover using Jquery

后端 未结 2 1912
孤城傲影
孤城傲影 2021-01-23 19:57

First of all please dont suggest me to do this using css.

I need to toggle between two images on-hover using Jquery. I need that two images (two toggling images

2条回答
  •  不要未来只要你来
    2021-01-23 20:51

    Here's the Quick Demo of below Code : http://jsbin.com/itunu

    HTML :

    
    
    
    
    
    Hello world !!
    
    
    
      
    
    
    

    Javascript :

    var a = [];
    
    a[0] = "http://i577.photobucket.com/albums/ss219/music_munster/powerpuff-girls-092.jpg";
    a[1] = "http://img.listal.com/image/459059/500full.jpg";
    
    
    $(document).ready(function() {
      var source = $.preload(a); 
      $('img').attr('src',source[0].src); //just an acknowledgement (pre-loading done)
      $('img').hover(function() {
        $('img').attr('src',source[1].src);
      },function() {
        $('img').attr('src',source[0].src);    
      });
    
    });
    
    
    
    //Image Preloading....  
    var cache = [];
      $.preload = function(arr) {
        for(var i = 0; i

提交回复
热议问题