gpt4 book ai didi

javascript - jQuery 滑出动画

转载 作者:太空宇宙 更新时间:2023-11-03 21:46:40 27 4
gpt4 key购买 nike

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

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

下面是我的 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com