javascript - Overlay div over an image -


i trying overlay div on image. doing using mouseenter , mouseleave events. using knockout data binding.

<ul class="gallery" data-bind="foreach: images">         <li>             <img data-bind="attr: {src:turl},event: {mouseenter: $parent.showoverlay, mouseleave: $parent.hideoverlay}" />         </li> </ul>  <div class="list-overlay overlay">     <img src="/content/images/play.png" /> watch </div> 

javascript:

showoverlay: function (data, event) {         var position = $(event.currenttarget).position();         var height = $(event.currenttarget).innerheight();         var width = $(event.currenttarget).innerwidth();          $(".list-overlay").css("top", parseint(position.top) + parseint(height) - 40);         $(".list-overlay").css("left", position.left);         $(".list-overlay").css("width", width)         $(".list-overlay").show();      },     hideoverlay: function () {         $(".list-overlay").hide();     } 

above code works fine show overlay. if start moving mouse on overlay starts flickering firing mouseleave , mouseenter again , again. tried using mouseleave , mouseout behavior same.

you need bind mouseleave overlay. , @ start hideoverlay() check if pointer entering overlay (from image) or image (from overlay), if stop function returning, check can use event.relatedtarget


Comments

Popular posts from this blog

Regex find and replace between <div class="customclass"> and </div> tag -

frame rate - JAVA simple fps animation(how can i work with?) -