javascript - jQuery - 如何同时应用 .animate() 和 .show ('slide' )?

标签 javascript jquery html css

在这个演示中 http://jsfiddle.net/vHcXN你可以看到当你点击链接时,转换开始了。先是div高度变化,然后是滑动效果。

如何同时制作两个作品?

 $(".turn_next").click(function(){
     $(".box2").hide();
     $(".box1_content").animate({height:'300px'}, 300,function(){
         $(".box3").show('slide', {direction: 'right'}, 500);
     });
 });

 $(".turn_back").click(function(){
     $(".box3").hide();
     $(".box1_content").animate({height:'100px'}, 300,function(){
         $(".box2").show('slide', {direction: 'left'}, 500);
     });
 });

最佳答案

从第一个动画的回调中移除第二个动画,

$(".turn_next").click(function(){
    $(".box2").hide();
    $(".box1_content").animate({height:'300px'}, 300);
    $(".box3").show('slide', {direction: 'right'}, 500);
 });

 $(".turn_back").click(function(){
    $(".box3").hide();
    $(".box1_content").animate({height:'100px'}, 300);
    $(".box2").show('slide', {direction: 'left'}, 500);
 });

您在回调函数 中指定的动画效果仅在初始动画完成后才会触发。这就是为什么您会看到这种效果。

DEMO

关于javascript - jQuery - 如何同时应用 .animate() 和 .show ('slide' )?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20667047/

相关文章:

javascript - document.getElementById ("id").value 正在工作,但 $('#id).val 不起作用

javascript - 在 firefox 中运行 node.js 和 socket.io 时出现 CORS 错误

javascript - HTTP 响应中缺少 react-admin

javascript - 如果另一个已经被触发,则仅触发一次

javascript - 绘制平行四边形 HTML5 Canvas

html - 将 <svg> HTML5 保存为 PNG 或图像

javascript - 在 Angular 应用程序的标题部分使用 CSS 或 JS 进行点击可展开文本

javascript - jquery animate.scrollTop() 在 mdl 链接中不起作用

javascript - jquery 创建输入时出现的问题无法为创建的元素创建限制

jquery - 如何使用CSS在中心并排对齐5个div?