如何添加 keyfram3 从右向左移动

发布于 2025-01-10 06:46:41 字数 3680 浏览 0 评论 0原文

我有 html 格式的卡片项目。

如您所见,有 8 个卡牌项目。我想要实现的是我想添加一个关键帧以将其从右向左移动,当我将鼠标悬停在其中一个卡片项目上时,我希望它停止。因为我想要它像链条一样不断地翻转,所以我不知道该怎么做。我可以只用css来实现这个吗?

.card {
  list-style: none;
  position: relative;
  filter: brightness(0.9) saturate(0);
}

.card:before {
  content: "";
  display: block;
  padding-bottom: 150%;
  width: 100%;
}

.card-background {
  background-size: cover;
  background-position: center;
  border-radius: 24px;
  bottom: 0;
  filter: brightness(0.75) saturate(1.2) contrast(0.85);
  left: 0;
  position: absolute;
  right: 0;
  top: 0;
  transform-origin: center;
  trsnsform: scale(1) translateZ(0);
  transition: filter 200ms linear, transform 200ms linear;
}

.card:hover {
  filter: unset;
}

.card:hover .card-background {
  transform: scale(1.05) translateZ(0);
  cursor: pointer;
}
<div class="row">
  <div class="col-md-2">
    <div class="card">
      <div class="card-background" style="background-image: url(https://images.unsplash.com/photo-1557177324-56c542165309?ixlib=rb-1.2.1&auto=format&fit=crop&w=1950&q=80)">
      </div>
    </div>
  </div>
  <div class="col-md-2">
    <div class="card">
      <div class="card-background" style="background-image: url(https://images.unsplash.com/photo-1557177324-56c542165309?ixlib=rb-1.2.1&auto=format&fit=crop&w=1950&q=80)">
      </div>
    </div>
  </div>
  <div class="col-md-2">
    <div class="card">
      <div class="card-background" style="background-image: url(https://images.unsplash.com/photo-1557177324-56c542165309?ixlib=rb-1.2.1&auto=format&fit=crop&w=1950&q=80)">
      </div>
    </div>
  </div>
  <div class="col-md-2">
    <div class="card">
      <div class="card-background" style="background-image: url(https://images.unsplash.com/photo-1557187666-4fd70cf76254?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=800&q=60)">
      </div>
    </div>
  </div>
  <div class="col-md-2">
    <div class="card">
      <div class="card-background" style="background-image: url(https://images.unsplash.com/photo-1556680262-9990363a3e6d?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=800&q=60)">
      </div>
    </div>
  </div>
  <div class="col-md-2">
    <div class="card">
      <div class="card-background" style="background-image: url(https://images.unsplash.com/photo-1557004396-66e4174d7bf6?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=800&q=60)">
      </div>
    </div>
  </div>
  <div class="col-md-2">
    <div class="card">
      <div class="card-background" style="background-image: url(https://images.unsplash.com/photo-1556680262-9990363a3e6d?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=800&q=60)">
      </div>
    </div>
  </div>
  <div class="col-md-2">
    <div class="card">
      <div class="card-background" style="background-image: url(https://images.unsplash.com/photo-1557004396-66e4174d7bf6?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=800&q=60)">
      </div>
    </div>
  </div>
</div>

但我没有添加关键帧,因为我不知道如何制作它。从字面上看,我正在努力实现完全转向,就像当它从窗户出去时,其他东西应该无限地出现。

I have card items in html.

As you see there are 8 card items. What I am trying to achieve is I want to add a keyframe to move that from right to left and when I hover over one of the card items, I want it to stop. Since I want it continuously like a chain turn over and over, I couldn't figure out how to do it. Can I achieve this only with css?

.card {
  list-style: none;
  position: relative;
  filter: brightness(0.9) saturate(0);
}

.card:before {
  content: "";
  display: block;
  padding-bottom: 150%;
  width: 100%;
}

.card-background {
  background-size: cover;
  background-position: center;
  border-radius: 24px;
  bottom: 0;
  filter: brightness(0.75) saturate(1.2) contrast(0.85);
  left: 0;
  position: absolute;
  right: 0;
  top: 0;
  transform-origin: center;
  trsnsform: scale(1) translateZ(0);
  transition: filter 200ms linear, transform 200ms linear;
}

.card:hover {
  filter: unset;
}

.card:hover .card-background {
  transform: scale(1.05) translateZ(0);
  cursor: pointer;
}
<div class="row">
  <div class="col-md-2">
    <div class="card">
      <div class="card-background" style="background-image: url(https://images.unsplash.com/photo-1557177324-56c542165309?ixlib=rb-1.2.1&auto=format&fit=crop&w=1950&q=80)">
      </div>
    </div>
  </div>
  <div class="col-md-2">
    <div class="card">
      <div class="card-background" style="background-image: url(https://images.unsplash.com/photo-1557177324-56c542165309?ixlib=rb-1.2.1&auto=format&fit=crop&w=1950&q=80)">
      </div>
    </div>
  </div>
  <div class="col-md-2">
    <div class="card">
      <div class="card-background" style="background-image: url(https://images.unsplash.com/photo-1557177324-56c542165309?ixlib=rb-1.2.1&auto=format&fit=crop&w=1950&q=80)">
      </div>
    </div>
  </div>
  <div class="col-md-2">
    <div class="card">
      <div class="card-background" style="background-image: url(https://images.unsplash.com/photo-1557187666-4fd70cf76254?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=800&q=60)">
      </div>
    </div>
  </div>
  <div class="col-md-2">
    <div class="card">
      <div class="card-background" style="background-image: url(https://images.unsplash.com/photo-1556680262-9990363a3e6d?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=800&q=60)">
      </div>
    </div>
  </div>
  <div class="col-md-2">
    <div class="card">
      <div class="card-background" style="background-image: url(https://images.unsplash.com/photo-1557004396-66e4174d7bf6?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=800&q=60)">
      </div>
    </div>
  </div>
  <div class="col-md-2">
    <div class="card">
      <div class="card-background" style="background-image: url(https://images.unsplash.com/photo-1556680262-9990363a3e6d?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=800&q=60)">
      </div>
    </div>
  </div>
  <div class="col-md-2">
    <div class="card">
      <div class="card-background" style="background-image: url(https://images.unsplash.com/photo-1557004396-66e4174d7bf6?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=800&q=60)">
      </div>
    </div>
  </div>
</div>

But I didnt add my keyframe because I dont know how can I make it. Literally, I am trying to achieve full turn, like when it goes out from the window something else should come infinitely.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦中的蝴蝶 2025-01-17 06:46:41

在你的 css 文件中使用它。

.card {
  list-style: none;
  position: relative;
  filter: brightness(0.9) saturate(0);
  width: 10%;
  animation: lefttoright 5s linear 2s infinite alternate; //name duration timing-function delay count direction 
}
@keyframes lefttoright {
  0%{
    left: 0;
  }
  50%{
    left: 50%;
  }
  100%{
    left: 0;
  }
}

.card:hover {
  filter: unset;
  animation-play-state: paused; //stop animation when hover on each item
}

完成了。

Use this in your css file.

.card {
  list-style: none;
  position: relative;
  filter: brightness(0.9) saturate(0);
  width: 10%;
  animation: lefttoright 5s linear 2s infinite alternate; //name duration timing-function delay count direction 
}
@keyframes lefttoright {
  0%{
    left: 0;
  }
  50%{
    left: 50%;
  }
  100%{
    left: 0;
  }
}

.card:hover {
  filter: unset;
  animation-play-state: paused; //stop animation when hover on each item
}

It's done.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文