javascript - jQuery 滑出动画

标签 javascript jquery html css

我正在为我正在进行的元素制作滑出栏,但我很难让动画正常工作。

我的目标是让它从左向右滑出,而不是像现在这样从顶部出现。

下面是我的 jQuery 代码和我的 jsfidde

提前致谢 乔治

http://jsfiddle.net/tXye8/

$(document).ready(function(){
var $button = $('#sideoutButton');
var $contain = $('#slideoutContain');
var containWidth = $('#slideoutContain').width();

//Hide the box
$contain.hide();

//Hide or show the container on button click
$button.click(function(){
    if ($contain.is(":visible")) {
        $contain.hide();
        $button.css("left", 0);
    }
    else {
        $contain.show(400, buttonMove());
    }
});

function buttonMove(){
    $button.css("left", function(value) {
        return 0 + containWidth;
    });
}
  });

最佳答案

如果您知道它应该有多宽,您可以使用 CSS 实现:

#mycontainer {
    width: 0;
    transition: width 400ms ease;
}

#mycontainer.expand {
    width: 400px; //or whatever your width is
}

只需使用 JS/jQuery 在 #mycontainer 上切换一个类

关于javascript - jQuery 滑出动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20255535/

相关文章:

Java Applet 和 html 页面 - 嵌入多个 applet

javascript - 将 html 表添加到 jQuery 加载的内容中

javascript - 在 Backbone.js 中,如何阻止事件传递到父 View ?

jQuery mouseup 没有被正确检测到

javascript - jQuery:为什么 jQuery.inArray() 不起作用?

javascript - 为什么 jquery sortable 不适用于 Canvas ?

javascript - 如何在我的手指移动时一直使用 jquery mobile 获取 XY 坐标?就像桌面的 mousemove

javascript - 如何从 javascript 发布 json?

javascript - 混淆嵌套测试套件和规范的执行顺序

javascript - 如何使用 jQuery 获取元素中的所有输入?