javascript - How to fade image src attribute? -
i found can done this:
$(".topimage img") .mouseover(function() { var src = $(this).attr("src").match(/[^\.]+/) + "-bw.png"; $(this).fadeout("fast").attr("src", src).fadein("fast"); }) .mouseout(function() { var src = $(this).attr("src").replace("-bw.png", ".png"); $(this).fadeout("fast").attr("src", src).fadein("fast"); }); });
but makes bad because fades previous src out completely. there way transition src change there no "now it's white background before new src loads in" ?
edit
<div class="topimage"> <img src="<?=$img[0]?>"> </div>
this how must remain - 1 image in topimage
container haveing 2 images change opacity, not option.
you can without js @ all. there lot of way it, here 1 : http://codepen.io/mbrillaud/pen/mwwgwz
html
<div class="container"> <img src="//lorempicsum.com/futurama/350/200/2" alt="" /> <img src="//lorempicsum.com/futurama/350/200/1" alt="" /> </div>
css
.container { position: relative; } .container img { position: absolute; top: 0; left: 0; transition: opacity 0.5s; } .container img:last-child:hover{ opacity: 0; }
Comments
Post a Comment