jquery - 使用 jQuery 隐藏和显示面板

标签 jquery html css

我想知道如何隐藏附加的面板,只有红色按钮显示在浏览器窗口的左侧,当我单击红色按钮时显示整个面板。如果我再次单击红色按钮,浏览器窗口左侧的面板会再次消失吗?

panel

我知道我应该使用与相对定位的包装器 div 相关的绝对定位,但这就是我的全部想法...

<div class="wrapper"><div id="panel"></div><!-- #panel --><p>content</p></div><!-- .wrapper -->

.wrapper {position: relative; margin: 0 auto; width: 800px; height: 500px;}

#panel {position: absolute; left: -150px; top: 50px;}

最佳答案

这是一个非常简单的例子,它使用animate()处理显示和隐藏的函数:

jQuery:

$('#click').click(function()
{
    $("#panel").animate({width:'toggle'},500);       
});

Working Demo Available here

CSS(来自演示):

//The content panel
#panel
{
     height: 500px;
     width: 200px;
     background: black;
     float: left;
     display: none;    
     color: white;
     font-size: xx-large;
}

//The tab
#click
{
     height: 50px;
     width: 25px;
     background: red;
     float: left; 
     margin-top: 200px;
}

相关 HTML:

<div id='panel'>[Put your content here]</div>
<div id='click'>

关于jquery - 使用 jQuery 隐藏和显示面板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7017788/

相关文章:

php - 在引导模式中通过 Ajax 检查并提交表单

jquery - 文本区域高度增加

javascript - Google Extension 在 Google Webstore 或 Extension Gallery 上工作?

html - 无论浏览器大小如何,如何将此 Google Logo 居中?

css - 响应式网站的媒体查询最小宽度 VS 最大宽度

css - AngularJS:通过流畅的动画增加减少div高度

javascript - 为表格中红色背景的行添加跑马灯效果

jquery - 滚动垂直溢出,同时仍然允许水平溢出

jquery - 如何通过单击屏幕上的空白点来关闭汉堡菜单? (类 : overlay-burger)

jquery - IE 中的 CSS 问题