Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
539 views
in Technique[技术] by (71.8m points)

html - 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)

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="image176630.jpg" alt="">
        <div class="hover-div">
          <div class="item">
            <img src="imageactive-my-list.png" alt="">
            <img src="imageactive-favourite.png" alt="">
            <img src="imageactive-watch-later.png" alt="">
          </div>
        </div>
    </div>
    <h5>2015 / Fiction, Drama</h5>
    <h4>The Wolf Of Wall Street</h4>
  </div>
</div>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can try adding the onmouseout and onmouseover attr to the image, not the div.

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...