jQuery 动画函数 - 隐藏和拉伸 div
我有一个带有 div 的页面;
<div id="container">
<div id="header"></div>
<div id="sidebar">
<div id="switch"></div>
<div id="list"></div>
</div>
<div id="viewer"></div>
<div id="footer"></div>
</div>
id switch
是一个触发器,用于切换动画。第一次点击时,它应该将 sidebar
的宽度缩小到 5px,list
的宽度缩小到 0px,switch
的 margin-left 缩小到 5px viewer
的左侧为 5px。当用户再次单击触发器时,一切可能会返回到之前的状态和位置。简而言之,我想切换隐藏/显示侧边栏。动画应该是向左然后向右滑动的效果。
I have a page with divs as;
<div id="container">
<div id="header"></div>
<div id="sidebar">
<div id="switch"></div>
<div id="list"></div>
</div>
<div id="viewer"></div>
<div id="footer"></div>
</div>
id switch
is a trigger, which is meant to toggle animation. On 1st click, it should shrink the width of sidebar
to 5px and width of list
to 0px, and the margin-left of switch
to 5px and the left of viewer
to 5px. When user again click the trigger, everything may return to previous state and positions. In short i want to toggle hide/show sidebar. The animations should be some sliding effect towards left and then towards right.
You can have a look at what I am talking about here and an updated fiddle here.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你的代码工作得很好,只是你的CSS需要微调。
请参阅此处的代码:http://jsfiddle.net/EzAV2/8/
Your code works fine, it is just your css that needs the fine tuning.
See the codes here: http://jsfiddle.net/EzAV2/8/
根据您更新的代码,当您给 #switch 的边距为 200px 时,您正在设置它的“left”;
改变、
至、
Per your updated code, you are setting the "left" of the #switch when you gave it a margin of 200px;
change,
to,