javascript - Prevent hovering effect after pointer moves away -


i want display element on hover. following code it. there problem, if hover on multiple times, element keeps displaying many times when cursor goes away.

hover on link multiple times in demo understand problem.

$('li').hover(function() {    $(this).find('.box').delay(100).fadein();  }, function() {    $(this).find('.box').delay(100).fadeout('fast');  });
.box {    color: #fff;    width: 200px;    background: #000;    position: absolute;    display: none;    margin-top: 50px;  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <div id="images">    <li>      show      <div class="box">        lorem ipsum dolor sit amet, consectetur adipiscing elit. fusce eu condimentum odio, non congue quam. cras feugiat nulla @ mattis semper.      </div>    </li>  </div>

jsfiddle https://jsfiddle.net/e99afrg8/

jquery animations queued default. so, hover on , off rapidly, animations queued , continue playing after stop hovering.

i suggest using stop() "[s]top currently-running animation on matched elements."

in example, have chosen clear queue not jump end of current animation. may want experiment values , see behavior prefer.

.stop( [clearqueue ] [, jumptoend ] )

$('li').hover(function() {    $(this).find('.box').stop(true,false).delay(100).fadein();  }, function() {    $(this).find('.box').stop(true,false).delay(100).fadeout('fast');  });
.box {    color: #fff;    width: 200px;    background: #000;    position: absolute;    display: none;    margin-top: 50px;  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <ul id="images">    <li>      show      <div class="box">        lorem ipsum dolor sit amet, consectetur adipiscing elit. fusce eu condimentum odio, non congue quam. cras feugiat nulla @ mattis semper.      </div>    </li>  </ul>


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -