首頁  >  問答  >  主體

如何懸停在一個物件上,使其消失,然後另一個物件出現,以便我可以點擊它?

我的第一個物件是「dog-letter」類別的物件。它有兩個類別為“狗”和“字母”的物件。我設法讓它在懸停後消失。 我的第二個物件是一個帶有“狗鼻子”類別的黑色圓圈。 但是這個物件出現後我無法點擊它。

更新

使用 z-index:1 後,第一個物件給出了一致性,但我仍然無法每次都點擊第二個物件。 如果我稍微移動遊標一點,就無法點擊。

.dog-letter-box {
  border-top: 1px solid #555;
  border-bottom: 2px solid #000000;
  height: 250px;
  width: 100%;
  background: #FEEEEB;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr 1fr;
  grid-template-rows: 1fr 1fr;
}

.dog-letter {
  z-index:1;
  margin: 6% auto;
  width: 50px;
  height: 150px;
  background: #00EFFE;
  animation-duration: 0.75s;
  animation-iteration-count: 1;
  animation-fill-mode: forwards;
  transform-origin: 50% 40%; 
  grid-column-start: 3;
  grid-column-end: 4;
  grid-row-start: 1;
}
.dog {
  width: 50px;
  height: 50px;
  clip-path: circle(40%);
  background: #FFB6C1;
}
.letter {
  width: 50px;
  height: 100px;
  clip-path: polygon(20% 0%, 80% 0%, 100% 100%, 0% 100%);
  background: #FF46C1;
}
.dog-letter:hover + .dog-nose {
  animation-duration: 0.75s;
  animation-iteration-count: 1;
  animation-fill-mode: forwards;
  animation-name: show-up;
  animation-timing-function: ease;
  
}
.dog-nose {
  margin:10px auto;
  width: 70px;
  height: 70px;
  background: #AFE1AF;
  grid-column-start: 3;
  grid-column-end: 4;
  grid-row-start: 1;
  opacity: 0;
}
.bounce:hover {
    animation-name: bounce-up;
    animation-timing-function: ease;
}
@keyframes bounce-up {
  0%   { transform: translateY(0) scaleY(1) rotateY(0); opacity: 1; }
  100% { transform: translateY(-15px) scaleY(0.2) rotateY(540deg); opacity: 0; }
}
@keyframes show-up {
  0% {opacity: 0;}
  100% {opacity: 1;}
}
<div class="dog-letter-box">
  <div class="dog-letter bounce">
      <div class="dog">55</div>
      <div class="letter">66</div>
  </div>
  <a class="dog-nose" href='http://www.google.com'>
    <svg viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg">
  <circle cx="10" cy="10" r="10"/>
</svg>
  </a>
</div>

P粉817354783P粉817354783182 天前370

全部回覆(1)我來回復

  • P粉425119739

    P粉4251197392024-04-02 11:42:40

    您的程式碼依賴懸停 .dog-letter ,這不好,您可以在懸停包含它們的框(.dog-letter,.dog-nose)時運行動畫。 我用的是.dog-letter-box,你可以新增一個新的div並將.dog-letter,.dog-nose放入其中。

    此外,我在懸停後使用pointer-events:none 作為狗字母,可以懸停狗鼻子並點擊連結。

    .dog-letter-box {
      border-top: 1px solid #555;
      border-bottom: 2px solid #000000;
      height: 250px;
      width: 100%;
      background: #FEEEEB;
      display: grid;
      grid-template-columns: 1fr 1fr 1fr 1fr 1fr;
      grid-template-rows: 1fr 1fr;
    }
    
    .dog-letter {
      z-index:1;
      margin: 6% auto;
      width: 50px;
      height: 150px;
      background: #00EFFE;
      animation-duration: 0.75s;
      animation-iteration-count: 1;
      animation-fill-mode: forwards;
      transform-origin: 50% 40%; 
      grid-column-start: 3;
      grid-column-end: 4;
      grid-row-start: 1;
    }
    .dog {
      width: 50px;
      height: 50px;
      clip-path: circle(40%);
      background: #FFB6C1;
    }
    .letter {
      width: 50px;
      height: 100px;
      clip-path: polygon(20% 0%, 80% 0%, 100% 100%, 0% 100%);
      background: #FF46C1;
    }
    .dog-letter-box:hover .dog-nose {
      animation-duration: 0.75s;
      animation-iteration-count: 1;
      animation-fill-mode: forwards;
      animation-name: show-up;
      animation-timing-function: ease;
      
    }
    .dog-nose {
      margin:10px auto;
      width: 70px;
      height: 70px;
      background: #AFE1AF;
      grid-column-start: 3;
      grid-column-end: 4;
      grid-row-start: 1;
      opacity: 0;
    }
    .dog-letter-box:hover .bounce {
      animation-name: bounce-up;
      animation-timing-function: ease;
      pointer-events: none;
    }
    @keyframes bounce-up {
      0%   { transform: translateY(0) scaleY(1) rotateY(0); opacity: 1; }
      100% { transform: translateY(-15px) scaleY(0.2) rotateY(540deg); opacity: 0; }
    }
    @keyframes show-up {
      0% {opacity: 0;}
      100% {opacity: 1;}
    }
    55
    66

    回覆
    0
  • 取消回覆