如何在JS中暂时暂停过渡 /转换效应?

发布于 2025-01-21 13:33:49 字数 1415 浏览 3 评论 0原文

我正在尝试使用CSS和JS的翻转卡的简单动画效果,我尝试了这种方法(这是行不通的):

CSS:

.card {
    user-select: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    width: 60px;
    height:60px;
    text-align:center;
    border: 0px;
    background-color: white;
    border-color: lightgrey;
    border-style:solid;
    border-width:2px;
    border-radius:10%;
    font-family:Verdana, Geneva, Tahoma, sans-serif;
    font-size:larger;
    font-weight: bold;
    transition: transform 0.5s;
}

.notransition {
  -webkit-transition: none !important;
  -moz-transition: none !important;
  -o-transition: none !important;
  transition: none !important;
}

HTML:

<div id="card1" class="card">

JS:

var card = document.getElementById('card1')
card.classList.add('notransition'); // disable transition
card.style.transform = 'scale(0,1)'; // set xscale = 0
card.classList.remove('notransition'); // reenable transition
card.style.transform = 'scale(1,1)'; // animate it to xscale = 1

我尝试过它(没有成功):

var card = document.getElementById('card1')
card.style.transition = 'none';
card.style.transform = 'scale(0,1)';
card.style.transition = 'transform 0.5s';
card.style.transform = 'scale(1,1)';

在这两种情况下,我都没有得到任何错误,它都不会显示任何过渡。

我在这里做错了什么?

I am trying a simple animation effect of a flipping card using CSS and JS and I tried this approach (that is not working):

CSS:

.card {
    user-select: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    width: 60px;
    height:60px;
    text-align:center;
    border: 0px;
    background-color: white;
    border-color: lightgrey;
    border-style:solid;
    border-width:2px;
    border-radius:10%;
    font-family:Verdana, Geneva, Tahoma, sans-serif;
    font-size:larger;
    font-weight: bold;
    transition: transform 0.5s;
}

.notransition {
  -webkit-transition: none !important;
  -moz-transition: none !important;
  -o-transition: none !important;
  transition: none !important;
}

HTML:

<div id="card1" class="card">

JS:

var card = document.getElementById('card1')
card.classList.add('notransition'); // disable transition
card.style.transform = 'scale(0,1)'; // set xscale = 0
card.classList.remove('notransition'); // reenable transition
card.style.transform = 'scale(1,1)'; // animate it to xscale = 1

I tried it either (no success):

var card = document.getElementById('card1')
card.style.transition = 'none';
card.style.transform = 'scale(0,1)';
card.style.transition = 'transform 0.5s';
card.style.transform = 'scale(1,1)';

In both cases I don't get any error, it just won't display any transition.

What am I doing wrong here?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文