简体   繁体   中英

How to hide text when a div translates over it on hover?

My preview div items are scaling on hover. What I want is to turn the opacity for title to zero when the first child is hovered upon. Is there any easy way to do this?

Right now it looks like this - https://i.ibb.co/mF64DdR/Screenshot-28.png

<div className="collection-preview">
<h1 className="title">{title.toUpperCase()}</h1>
  <div className="preview"> 
  {     
        movies
        ? (movieData.map(({id, ...otherProps}) => <CollectionItem key={id} {...otherProps} />))
        : null
  }
  {
        tvshow
        ? (tvData.map(({id, ...otherProps}) => <CollectionItem key={id} {...otherProps} />))
        : null
  }
  </div>
    </div>

You could try something like:

let title = document.querySelector('.title');
let preview = document.querySelector('.preview');
preview.addEventListener('mouseover', function(){
   title.setAttribute("style", "opacity:0;")
})

However, I would add a class to each CollectionItem so you could add the eventListener to each preview item instead of the parent.

If you are using react hooks you could also use useHover. https://usehooks.com/useHover/

You can just use CSS to hide any text on hover

.title:hover{
   display: none;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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