如何使用幻灯片效果(jquery)为宽度设置动画?

Posted

技术标签:

【中文标题】如何使用幻灯片效果(jquery)为宽度设置动画?【英文标题】:How to animate the width with slide effect (jquery)? 【发布时间】:2013-06-11 21:23:37 【问题描述】:

如何使用向右滑动效果为宽度设置动画?

这是我的代码:

$(".toggle").click(function()
  $(".wrapper").animate( width: "80%" );
);

谢谢!

【问题讨论】:

【参考方案1】:

你可以这样做:

$(".toggle").click(function () 
    $(".wrapper").animate(
        width: "80%"
    , 
        duration: 1000,
        specialEasing: 
            width: 'linear'
        
    );
);

FIDDLE DEMO

【讨论】:

@JensKvist 随意标记answer as accepted 还有一个问题,点击它时如何阻止它进入页面顶部? toggle 元素是按钮还是锚点?如果一个锚你需要使用event.preventDefault()..【参考方案2】:
$("#go").click(function()
  $("#block").animate(
  width: "70%"
  , 1500 );
);

【讨论】:

以上是关于如何使用幻灯片效果(jquery)为宽度设置动画?的主要内容,如果未能解决你的问题,请参考以下文章