jQuery没有动画
jQuery not animating back up
我有一个框,它应该在点击时淡入并向上移动,但相反,它只是停留在下面。褪色作品
谢谢你的帮助!
var fadeInDown = function (element, duration, easing) {
element.css({
opacity: '0',
webkitTransform: 'translateY(100%)',
transform: 'translateY(100%)',
})
.animate({
opacity: '1',
webkitTransform: 'translateY(0%)',
transform: 'translateY(0%)',
}, duration, easing);
};
$('.box').click(function () {
fadeInDown($('.box'), 400, 'swing');
});
body {
display: flex;
justify-content: center;
}
.box {
width: 200px;
height: 200px;
background: pink;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="box"></div>
jQuery的animate不支持这样的css变换。你需要引入阶跃函数,让它动起来。这应该是你想要的:
var fadeInDown = function (element, duration, easing) {
element.css({
opacity: '0',
webkitTransform: 'translateY(0%)',
transform: 'translateY(0%)',
})
.animate({
opacity: '1'
}, {
duration: duration,
step: function(now, fx) {
var step = 100*now;
$(this).css({
webkitTransform: 'translateY(' + step + '%)',
transform: 'translateY(' + step + '%)'
});
}
}, easing);
};
$('.box').click(function () {
fadeInDown($('.box'), 400, 'swing');
});
body {
display: flex;
justify-content: center;
}
.box {
width: 200px;
height: 200px;
background: pink;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="box"></div>
还有,看一下这个问题,它可能会给你一些额外的帮助。
相关文章:
- 如何简化动画jQuery代码
- 如何禁用可排序动画 Jquery
- 离开页面前的动画JQuery
- 动画Jquery弹出菜单
- 设置元素动画jquery
- 如何自动动画jquery画廊
- 缩放/动画 jQuery 拖放到可拖放时可拖动
- 卡片动画Jquery和CSS
- 拆分襟翼文本动画 Jquery
- 满足条件时禁用动画 jQuery
- 传递参数以动画 jquery 函数
- 延迟和动画 jQuery
- 获取动画 jQuery Java 脚本中行进的像素数
- 重新启动动画jquery和javascript
- 为什么这个脚本在页面加载后3秒没有动画(jquery)
- 菜单图标动画jQuery
- 制作无限动画jQuery
- 将延迟应用于动画jquery
- 添加滑动回调动画Jquery
- 使用动画 jquery 更改文本