jquery - Cross-fade div on mouse hover -
i want background image change when mouse hovers on each menu item. code works but, when images fadeout
, fadein
, there white flash in between. remove it, want images cross-fade instead of fading out , in.
how can achieve this?
$(document).ready(function() { $(".home-menu-list li a").mouseenter(function() { var bannerclass = '#home-banner-' + $(this).attr('id'); $('.active-banner').not(bannerclass).stop().fadeout().removeclass('active-banner'); $(bannerclass).stop().fadein().addclass('active-banner'); }); });
.main-banner-wrapper img { height: 50px; width: 100%; object-fit: cover; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="container-fluid "> <div id="home-banner-1" class="active-banner"> <div class="main-banner-wrapper"> <img src="http://farm6.staticflickr.com/5145/5576437826_940f2db110.jpg" alt="image 1" class="upload"> </div> <div class="col-md-4 col-sm-6 visible-lg visible-md visible-sm front-text"> <p>thethe world.</p> </div> </div> <div id="home-banner-2" style="display:none"> <div class="main-banner-wrapper"> <img src="http://farm4.staticflickr.com/3611/3463265789_586ce40aef.jpg" class="upload"> </div> <div class="col-md-4 col-sm-6 visible-lg visible-md visible-sm front-text"> <p>thethe world.</p> </div> </div> <div id="home-banner-3" style="display:none"> <div class="main-banner-wrapper"> <img src="http://farm6.staticflickr.com/5263/5601183065_f88a48d599.jpg" class="upload"> </div> <div class="col-md-4 col-sm-6 visible-lg visible-md visible-sm front-text"> <p>the around world.</p> </div> </div> </div> <!--content--> <div class="container-fluid"> <div class="main-logo-panel"> <div class="box"> <div class="col-md-12 col-sm-12 "> <div class="col-md-3 col-sm-3 col-xs-4 main-logo"></div> <div class="col-md-9 col-sm-9 col-xs-8 main-menu"> <ul class="list-inline home-menu-list"> <li><a href="#" id="1">rigging</a> </li> <li><a href="#" id="2">hatches </a> </li> <li><a href="#" id="3">stoppers</a> </li> </ul> </div> </div> </div> </div> </div>
view on jsfiddle
you can achieve same using css.
some small css changes:
add transition: opacity 1s ease-in-out;
.main-banner-wrapper img
and add following css:
.container-fluid .active-banner img { opacity:1; } .container-fluid img { opacity:0; }
and remove .fadeout()
, .fadein()
from jquery
see example on http://jsfiddle.net/m92aotbd/2/
Comments
Post a Comment