Replace Image With Rollover Fade
I am trying to replace an image with another image on rollover and use a fade. I have 2 images water_bag.jpg and water_bag-hover.jpg I am trying to replace one on rollover with the
Solution 1:
you are setting the src to just '-hover.jpg'
you need to do this to set it to the new image:
$('.my_img').parent().append($('.my_img').clone().attr('src',$('.my_img').attr('src').replace('.jpg','-hover.jpg')).fadeIn('slow'))
Solution 2:
Here's simple way: set one image as a background, and fade in another on top:
<imgsrc="http://i.imgur.com/vdDQgb.jpg"hoverImg="http://i.imgur.com/Epl4db.jpg">
JS:
$('body').find('*[hoverImg]').each(function(index){
$this = $(this)
$this.wrap('<div>')
$this.parent().css('width',$this.width())
$this.parent().css('height',$this.width())
$this.parent().css('background-image',"url(" + $this.attr('hoverImg')+")")
$this.hover(function() {
$(this).stop()
$(this).fadeTo('',.01)
},function() {
$(this).stop()
$(this).fadeTo('',1)
})
})
Post a Comment for "Replace Image With Rollover Fade"