jquery - 如何隐藏对象以开始其动画?

标签 jquery css delay

我编写了一个动画,然后通过 jquery 将其实现并延迟到我的 html 代码中。但后来我意识到动画并不顺利(它从一开始就消失了,然后正确地出现在屏幕上)。我想让这个对象隐藏 1.25 秒,然后同时开始播放动画。我在这个网站上显示我的代码时遇到了一些问题(堆栈溢出),对此深表歉意。

JS:

<script>
setTimeout( function(){
$('#myobject').addClass('animated bounceInLeft');
}, 1250)
</script>

CSS: `

 @-webkit-keyframes bounceInLeft {
    from, 60%, 75%, 90%, to {
    -webkit-animation-timing-function: cubic-bezier(0.215, 0.610, 0.355,1.000);
    animation-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
    }

    0% {
    opacity: 0;
    -webkit-transform: translate3d(-3000px, 0, 0);
    transform: translate3d(-3000px, 0, 0);
    }

    60% {
    opacity: 1;
    -webkit-transform: translate3d(25px, 0, 0);
    transform: translate3d(25px, 0, 0);
    }

    75% {
    -webkit-transform: translate3d(-10px, 0, 0);
    transform: translate3d(-10px, 0, 0);
    }

    90% {
    -webkit-transform: translate3d(5px, 0, 0);
    transform: translate3d(5px, 0, 0);
    }

    to {
    -webkit-transform: none;
    transform: none;
    }
    }
    @keyframes bounceInLeft {
    from, 60%, 75%, 90%, to {
    -webkit-animation-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
    animation-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
    }

    0% {
    opacity: 0;
    -webkit-transform: translate3d(-3000px, 0, 0);
    transform: translate3d(-3000px, 0, 0);
    }

    60% {
    opacity: 1;
    -webkit-transform: translate3d(25px, 0, 0);
    transform: translate3d(25px, 0, 0);
    }

    75% {
    -webkit-transform: translate3d(-10px, 0, 0);
    transform: translate3d(-10px, 0, 0);
    }

    90% {
    -webkit-transform: translate3d(5px, 0, 0);
    transform: translate3d(5px, 0, 0);
    }

    to {
    -webkit-transform: none;
    transform: none;
    }
    }

    .bounceInLeft {
    -webkit-animation-name: bounceInLeft;
    animation-name: bounceInLeft;
    } 

`

最佳答案

你应该添加 opacity:0; 到你的对象

这样直到动画开始才会显示

#myobject{
   opacity:0;
}

添加另一个 opacity:1; 的类并使其变得重要:

.visible{

  opacity:1!important;
}

并将其与其他类一起添加到您的脚本中

setTimeout( function(){
$('#myobject').addClass('animated bounceInLeft visible');
}, 1250)

这将使它在动画结束后保持可见。

Working demo

关于jquery - 如何隐藏对象以开始其动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40774038/

相关文章:

javascript - 旋转后获取元素的默认左侧和顶部位置

php - ajax图片上传和预览表单

jquery - Jquery的serialize方法有什么用

javascript - 如何在网页上隔离包含第 3 方 HTML 片段?

ios - 如何编程延迟?

css - 通过添加类触发的 css3 动画中不需要的延迟

JavaScript 计时器倒计时注销

html - 如何使用 DIV 布局 HTML 5

css - 如何使用 Angular JS 动态化我的 CSS

javascript - typescript 节拍器