【问题标题】:I want the animation to work on the progress bar when hovering on an a element当悬停在 a 元素上时,我希望动画在进度条上工作
【发布时间】:2021-09-18 00:14:04
【问题描述】:

这是我的 HTML 和 CSS:

.choosebybrand {
  position: relative;
  display: flex;
  width: 100%;
  height: auto;
  justify-content: space-around;
  flex-wrap: wrap;
  background: linear-gradient(to bottom, #ffffff, whitesmoke);
  margin-bottom: 0px;
  text-align: center;
  padding: 70px;
}

.choosebybrand img {
  box-shadow: 0px 5px 20px 1px rgba(0, 0, 0, 1);
  margin: 15px;
  border-radius: 20px;
}

.choosebybrandtext h1 {
  margin-top: 100px;
  left: 50%;
  text-align: center;
  color: rgb(255, 0, 68);
  font-size: 40px;
  font-style: italic;
}

.choosebybrand h3 {
  margin-top: 20px;
  font-size: 20px;
  font-family: 'Pacifico', 'cursive';
  color: rgba(0, 0, 0, 0.2);
  text-decoration: none;
}

.apple:hover h3,
.motorola:hover h3,
.lg:hover h3,
.samsung:hover h3,
.huawei:hover h3 {
  cursor: pointer;
  color: rgb(255, 0, 68);
  transition: 1s;
}

a:hover {
  text-decoration: none;
}

.icons a {
  margin: 10px;
}

.progress-bar {
  animation: pr 5s infinite;
  background-color: red;
}

@keyframes pr {
  0% {
    width: 0;
    color: red;
  }
  10% {
    background-color: blue;
  }
  20% {
    background-color: black;
  }
  30% {
    background-color: yellow;
  }
  40% {
    background-color: tomato;
  }
  50% {
    width: 100%;
    background-color: violet;
  }
  60% {
    background-color: rgb(184, 145, 145);
  }
  70% {
    background-color: white;
  }
  80% {
    background-color: rgb(0, 255, 234);
  }
  100% {
    width: 0;
    background-color: red;
  }
}
<div class="choosebybrandtext">
  <h1>Choose by Brand</h1>
</div>
<div style="margin-top: 50px" data-aos="fade-in" class="choosebybrand">
  <div class="samsung">
    <a href="samsung.html">
      <div class="frontimage">
        <img src="images/samsung.png" height="232px" width="115px" alt="">
      </div>
      <h3>Samsung</h3>
    </a>

  </div>
  <div class="apple">
    <a href="apple.html">
      <div class="frontimage">
        <img src="images/apple.png" height="232px" width="115px" alt="">
      </div>
      <H3>Apple</H3>
    </a>

  </div>
  <div class="lg">
    <a href="lg.html">
      <div class="frontimage">
        <img src="images/LG.png" height="232px" width="115px" alt="">
      </div>
      <h3>Lg</h3>
    </a>

  </div>
  <div class="motorola">
    <a href="motorola.html">
      <div class="frontimage">
        <img src="images/Motorola.png" height="232px" width="115px" alt="">
      </div>
      <h3>Motorola</h3>
    </a>

  </div>
  <div class="huawei">
    <a href="huawei.html">
      <div class="frontimage">
        <img src="images/huawei.png" height="232px" width="115px" alt="">
      </div>
      <h3>Huawei</h3>
    </a>
  </div>
</div>
<div class="progress">
  <div class="progress-bar"></div>
</div>

【问题讨论】:

标签: javascript html css bootstrap-4


【解决方案1】:
const element = document.querySelector(".element")
const progressBar = document.querySelector(".progress-bar")


element.addEventListener("mouseover", function() {
  progressBar.style.animation = "pr 5s infinite"
})

【讨论】:

    【解决方案2】:

    最好在元素上加上eventListener

    const element = document.querySelector(".element")
    const progressBar = document.querySelector(".progress-bar")
    
    
    element.addEventListener("mouseover", function() {
      progressBar.style.animation = "pr 5s infinite"
    })
    

    确保将 .element 替换为您自己的类

    【讨论】:

    • 它不工作@Rishi Ghosh
    • 您能否进一步详细说明发生的事情并告诉我们您希望将鼠标悬停在哪个元素上
    猜你喜欢
    • 1970-01-01
    • 2015-05-06
    • 1970-01-01
    • 2014-01-15
    • 2021-04-28
    • 2011-01-20
    • 2020-01-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多