Change the image source on rollover using jQuery

前端 未结 14 1214
隐瞒了意图╮
隐瞒了意图╮ 2020-11-22 10:23

I have a few images and their rollover images. Using jQuery, I want to show/hide the rollover image when the onmousemove/onmouseout event happen. All my image names follow t

14条回答
  •  眼角桃花
    2020-11-22 10:46

    
    
    
    
    img = {
    
     init: function() {
      $('img').on('mouseover', img.swap);
      $('img').on('mouseover', img.swap);
     }, 
    
     swap: function() {
      var tmp = $(this).data('swap');
      $(this).attr('data-swap', $(this).attr('src'));
      $(this).attr('str', tmp);
     }
    }
    
    img.init();
    

提交回复
热议问题