Wątek przeniesiony 2023-04-16 14:39 z JavaScript przez Riddle.

Uruchomienie animacji dopiero po przewinięciu

1

Cześć, robię takie ala "CV" na zaliczenie projektu. Chciałem dodać umiejętności w formie okrągłych pasków postępów które wyglądają tak:

image

W chwili obecnej paski ładują się od razu po wejściu na stronę, a chciałbym żeby robiły to dopiero gdy przewinę stronę w dół i będę na ich wysokości.
Kod js:

//sticky header//
const header = document.querySelector("header");
window.addEventListener("scroll", function () {
  header.classList.toggle("sticky", this.window.scrollY > 0);
});
// ....................................................................

let options = {
  startAngle: -1.55,
  size: 150,
  value: 0.85,
  fill: { gradient: ["#a445b2", "#fa4299"] },
};
$(".circle .bar")
  .circleProgress(options)
  .on("circle-animation-progress", function (event, progress, stepValue) {
    $(this)
      .parent()
      .find("span")
      .text(String(stepValue.toFixed(2).substr(2)) + "%");
  });
$(".js .bar").circleProgress({
  value: 0.7,
});
$(".react .bar").circleProgress({
  value: 0.6,
});

Index:

</section>
    <section class="skills" id="skills">
      <div class="wrapper">
        <div class="card">
          <div class="circle">
            <div class="bar"></div>
            <div class="box"><span>50%</span></div>
          </div>
          <div class="text">HTML & CSS</div>
        </div>
        <div class="card js">
          <div class="circle">
            <div class="bar"></div>
            <div class="box"><span>70%</span></div>
          </div>
          <div class="text">JavaScript</div>
        </div>
        <div class="card react">
          <div class="circle">
            <div class="bar"></div>
            <div class="box"><span>40%</span></div>
          </div>
          <div class="text">React JS</div>
        </div>
      </div>
    </section>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-circle-progress/1.2.2/circle-progress.min.js"></script>
    <script src="js/script.js"></script>

CSS:

.skills {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
  background: #202020;
}
.wrapper {
  width: 800px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
}
.wrapper .card {
  background: #fff;
  width: calc(33% - 20px);
  height: 300px;
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: space-evenly;
  flex-direction: column;
  box-shadow: 0px 10px 15px rgba(0, 0, 0, 0.1);
}
.wrapper .card .circle {
  position: relative;
  height: 150px;
  width: 150px;
  border-radius: 50%;
  cursor: default;
}
.card .circle .box,
.card .circle .box span {
  position: absolute;
  top: 50%;
  left: 50%;
}
.card .circle .box {
  height: 100%;
  width: 100%;
  background: #fff;
  border-radius: 50%;
  transform: translate(-50%, -50%) scale(0.8);
  transition: all 0.2s;
}
.card .circle:hover .box {
  transform: translate(-50%, -50%) scale(0.91);
}
.card .circle .box span,
.wrapper .card .text {
  background: -webkit-linear-gradient(left, #a445b2, #fa4299);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.circle .box span {
  font-size: 38px;
  font-family: sans-serif;
  font-weight: 600;
  transform: translate(-45%, -45%);
  transition: all 0.1s;
}
.card .circle:hover .box span {
  transform: translate(-45%, -45%) scale(1.09);
}
.card .text {
  font-size: 20px;
  font-weight: 600;
}
@media (max-width: 753px) {
  .wrapper {
    max-width: 700px;
  }
  .wrapper .card {
    width: calc(50% - 20px);
    margin-bottom: 20px;
  }
}
@media (max-width: 505px) {
  .wrapper {
    max-width: 500px;
  }
  .wrapper .card {
    width: 100%;
  }

Czy ktoś pomógł by mi pomóc rozwiązać ten problem, lub znaleźć informacje które by pomogły?

1

Do nasłuchiwania informacji o tym, czy dany element jest widoczny na ekranie służy Intersection Observer

1 użytkowników online, w tym zalogowanych: 0, gości: 1