简体   繁体   English

当 hover 在另一个子容器上时,使用 javascript 容器闪烁并同时删除和添加 CSS 类

[英]using javascript container blinking and remove and add CSS classes at same time when hover over another child container

I have a problem where I'm making a card photo 1 that contains an invisible child container that has buttons and when mouse over it appears above the parent element photo 2 , I have mouse out event that hides the child div and the problem is that the event occurs also when the mouse over the child div which cause the blinking of the child div (add CSS class that makes it visible and removes it at the same time, check attached gif )我有一个问题,我正在制作一张卡片照片 1 ,其中包含一个带有按钮的不可见子容器,当鼠标悬停在父元素照片 2上方时,我有隐藏子 div 的鼠标移出事件,问题是当鼠标悬停在导致子 div 闪烁的子 div 上时也会发生该事件(添加 CSS class 使其可见并同时将其删除,检查附加的 gif

 addHandlerHoverCardView(handler) { var card; // parent element is movie-list this._parentElement.addEventListener("mouseover", function (e) { card = e.target.closest(".card"); if (card,= null) { handler(card; 'show'). } }) this._parentElement,addEventListener('mouseout'. function (e) { const data = e.target.closest(';hover-div'), if (data;= null) { handler(card, 'hide'); } }) }
 <div class="movie-list"> <div class="movie-details"> <div class="card" onmouseout="hideBottomCard()" onmouseover="showBottomCard()"> <img src="image\176630.jpg" alt=""> <div class="hover-div"> <div class="item"> <img src="image\active-my-list.png" alt=""> <img src="image\active-favourite.png" alt=""> <img src="image\active-watch-later.png" alt=""> </div> </div> </div> <h5>2015 / Fiction, Drama</h5> <h4>The Wolf Of Wall Street</h4> </div> </div>

You can try adding the onmouseout and onmouseover attr to the image, not the div.您可以尝试将 onmouseout 和 onmouseover attr 添加到图像,而不是 div。

<div class="movie-list">
<div class="card"
      >
    <img src="image\176630.jpg" alt="" onmouseout="hideBottomCard()" onmouseover="showBottomCard()">
    <div class="hover-div">
      <div class="item">
        <img src="image\active-my-list.png" alt="">
        <img src="image\active-favourite.png" alt="">
        <img src="image\active-watch-later.png" alt="">
      </div>
    </div>
</div>
<h5>2015 / Fiction, Drama</h5>
<h4>The Wolf Of Wall Street</h4>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM