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

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

这是我的代码:

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

谢谢!

【问题讨论】:

    标签: javascript jquery jquery-animate width slide


    【解决方案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 );
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-18
      • 2014-02-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多