javascript - 在 jquery 中立即为 div 设置更大和更小的动画

标签 javascript jquery css

我想在 jQuery animate 中为大和小的 div 设置动画。我写了这段代码:

$(this).animate({
    opacity: 0,
    top: "-=100",
    width: "38px",
    height: "32px"
}, 1500, function () {
    $this.remove()
})

使用这段代码,大的 div 不会变小。我如何编辑此代码以首先使其变大 div 然后立即变小?如果可以在 CSS3 中完成这项工作,请帮助在 CSS3 中完成。

谢谢。

最佳答案

使用 CSS3 动画和 transform: scale(); 你可以做到:

@-webkit-keyframes grow
{
    0%{-webkit-transform:scale(1);}
    50%{-webkit-transform:scale(2);}
    100%{-webkit-transform:scale(1);}
}
@-moz-keyframes grow
{
    0%{-moz-transform:scale(1);}
    50%{-moz-transform:scale(2);}
    100%{-moz-transform:scale(1);}
}
@-ms-keyframes grow
{
    0%{-ms-transform:scale(1);}
    50%{-ms-transform:scale(2);}
    100%{-ms-transform:scale(1);}
}
#spin{
    position:absolute;
    top:10%;
    left:10%;
    -webkit-animation-name: grow;
    -webkit-animation-duration: 3s;
    -webkit-animation-iteration-count: infinite;
    -webkit-animation-timing-function: linear;
    -moz-animation-name: grow;
    -moz-animation-duration: 3s;
    -moz-animation-iteration-count: infinite;
    -moz-animation-timing-function: linear;
    -ms-animation-name: grow;
    -ms-animation-duration: 3s;
    -ms-animation-iteration-count: infinite;
    -ms-animation-timing-function: linear;
}

See this fiddle

关于javascript - 在 jquery 中立即为 div 设置更大和更小的动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36862563/

相关文章:

javascript - 在表单中使用setCustomValidity需要点击两次onsubmit

javascript - 在js中创建一个忽略时区的日期

html - 如果我有两个相同的元素,一个缩放到 2 倍,如何缩小它的内部元素并将其放置在 1 倍的位置?

javascript - 使用 jQuery 从本地存储中的数组中删除元素

javascript - 获取文本 block 中的元素索引

javascript - 重新排列数组的更直观方式

JQuery 验证插件在某些情况下需要电子邮件

javascript - 如何使用 jQuery 解决这个问题

c# - 通过 AJAX 从 C# 中的服务器返回数据

html - 如何让我的 Logo 在滚动时滚动?