Jquery-如何在中间重置动画'的当前动画
Jquery - How to reset Animation in the middle of it's current animation?
我正在进行我的第一个JQuery项目,我正试图弄清楚,如果用户决定用鼠标离开.contain,如何重置我的动画。现在,如果用户用鼠标离开.cantain,动画将继续进行,就好像它们仍然在.contain中一样。如果用户决定在动画中期离开容器,我希望它反向还原动画。我怎样才能做到这一点?
$( document ).ready(function() {
$('#facial span').fadeOut(0);
$('.container').mouseenter(function(){
// When mouse enters the .container, #facial slides to center of .container.
$('#facial').animate({right: '25%'})
// After #facial slides to center it delays for 500ms.
.delay(500)
// After #facial delays it expands it's width to 100% of .container.
.animate({right: 0, width: '100%'});
// show the span link at bottom as a H2 with center aligned.
$('span').fadeIn(600);
});
$('.container').mouseleave(function(){
// Mouse leaves .container, and span fades out slowly.
// $('span').css('display','none');
$('span').fadeOut(500);
// Mouse leaves the .container, #facial shrinks it's width to 50%.
// #facial slides back to right of .container.
$('#facial').animate({right: 0, width: '50%'});
});
});
这是我的演示
您可以使用jQuery的stop(true)
方法来取消所有当前和排队的动画。
请参阅此更新jsFiddle
尝试使用.stop(true, true, true)
var $view = $('<a href="x">View</a>');
$( document ).ready(function() {
$('#facial span').fadeOut(0);
$('.container').mouseenter(function(){
// When mouse enters the .container, #facial slides to center of .container.
$('#facial').animate({right: '25%'})
// After #facial slides to center it delays for 500ms.
.delay(500)
// After #facial delays it expands it's width to 100% of .container.
.animate({right: 0, width: '100%'});
// show the span link at bottom as a H2 with center aligned.
$('span').fadeIn(600);
});
$('.container').mouseleave(function(){
// Mouse leaves .container, and span fades out slowly.
// $('span').css('display','none');
$('span').stop(true, true, true).fadeOut(500);
// Mouse leaves the .container, #facial shrinks it's width to 50%.
// #facial slides back to right of .container.
$('#facial').stop(true, true, true).animate({right: 0, width: '50%'});
});
});
jsfiddlehttps://jsfiddle.net/sy4pv8z3/57/
相关文章:
- 如何简化动画jQuery代码
- 如何禁用可排序动画 Jquery
- 离开页面前的动画JQuery
- 动画Jquery弹出菜单
- 设置元素动画jquery
- 如何自动动画jquery画廊
- 缩放/动画 jQuery 拖放到可拖放时可拖动
- 卡片动画Jquery和CSS
- 拆分襟翼文本动画 Jquery
- 满足条件时禁用动画 jQuery
- 传递参数以动画 jquery 函数
- 延迟和动画 jQuery
- 获取动画 jQuery Java 脚本中行进的像素数
- 重新启动动画jquery和javascript
- 为什么这个脚本在页面加载后3秒没有动画(jquery)
- 菜单图标动画jQuery
- 制作无限动画jQuery
- 将延迟应用于动画jquery
- 添加滑动回调动画Jquery
- 使用动画 jquery 更改文本