【发布时间】:2020-05-10 16:27:30
【问题描述】:
我有一个图标,在加载时会反弹,然后在角落缩小。在悬停时,它会使用 transition: transform 正确放大和缩小。
我在 setInterval 和第一次加载时启动反弹。问题是在弹跳时它会缩放而不是轻松动画。它只是立即缩小。我在悬停时重复它工作正常。我希望在反弹之前和之后与悬停缩放动画相同。 JS解决方案也不错。
我尝试了各种方法并弄清楚如何使其工作,请指教。
window.setInterval(function() {
$( ".email" ).toggleClass( "bounceemail" );
}, 5000);
.bounceemail {
-webkit-animation-name: bounce;
animation-name: bounce;
-webkit-animation-duration: 2s;
animation-duration: 2s;
}
.email {
max-width: 150px;
position: fixed;
bottom: 0px;
right: 0px;
margin-bottom: 5px;
margin-right: 5px;
z-index: 70;
-webkit-filter: drop-shadow( 3px 3px 2px black);
transition: transform 0.3s;
transform: scale(0.6)translate(+35%, +35%);
transition-timing-function: ease-in;
}
.email:hover {
transition: transform 0.2s;
transform: scale(1)translate(0%, 0%);
transition-timing-function: ease-out;
}
@-webkit-keyframes bounce {
0%,
20%,
55%,
75%,
100% {
-webkit-transform: translateY(0);
}
40% {
-webkit-transform: translateY(-45px);
}
60% {
-webkit-transform: translateY(-35px);
}
}
@keyframes bounce {
0%,
20%,
55%,
75%,
100% {
-webkit-transform: translateY(0);
}
40% {
-webkit-transform: translateY(-45px);
}
60% {
-webkit-transform: translateY(-35px);
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<object data="your.svg" type="image/svg+xml">
<svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="home" class="svg-inline--fa fa-home fa-w-18 meni-pulse email bounceemail" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512"><path fill="currentColor" d="M280.37 148.26L96 300.11V464a16 16 0 0 0 16 16l112.06-.29a16 16 0 0 0 15.92-16V368a16 16 0 0 1 16-16h64a16 16 0 0 1 16 16v95.64a16 16 0 0 0 16 16.05L464 480a16 16 0 0 0 16-16V300L295.67 148.26a12.19 12.19 0 0 0-15.3 0zM571.6 251.47L488 182.56V44.05a12 12 0 0 0-12-12h-56a12 12 0 0 0-12 12v72.61L318.47 43a48 48 0 0 0-61 0L4.34 251.47a12 12 0 0 0-1.6 16.9l25.5 31A12 12 0 0 0 45.15 301l235.22-193.74a12.19 12.19 0 0 1 15.3 0L530.9 301a12 12 0 0 0 16.9-1.6l25.5-31a12 12 0 0 0-1.7-16.93z"></path></svg>
</object>
编辑 找到了一个正常工作的解决方案,它是图标的初始比例为 1(不像上面的版本那样更小),并且弹跳工作没有打嗝。在悬停时,我停止反弹并将其从 1 扩展到向上。这样就不会发生碰撞。
Aldo 看看是否有人会让这个版本正常工作会很有趣。
【问题讨论】:
标签: javascript jquery css animation