开发者

hide and show panel with jQuery

I wonder how can i hide the attached panel in a way that only the red button to be shown on the left side of the browser's window and when i click on the red button to appear the whole panel. If i click again on the red button, the panel to disappear again on the left side of the browser's window?

hide and show panel with jQuery

I know i should use absolute positioning related to a relative positioned wrapper div, but that's all my idea...

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

.wrapper {position开发者_StackOverflow社区: relative; margin: 0 auto; width: 800px; height: 500px;}

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


Here is a very simple example, it uses the animate() function to handle the showing and hiding:

jQuery:

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

Working Demo Available here

CSS (from demo):

//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;
}

Related HTML:

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


Check out jQuery UI effects for what you're trying to acheive:

http://jqueryui.com/demos/effect/


The provide solution is very basic and is targeted soley towards the onClick event and interaction.

HTML:

<div id="panel">Content
</div>
<div id="tab">+</div>

CSS:

#panel { width: 300px; height: 200px; background: #000; display: none; float: left; }
#tab { width: 50px; background: #FF0000; height: 50px; float: left; text-align: center;}

jQuery:

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

Working example available at: http://jsfiddle.net/5cdgw/


example jsfiddle

CSS:

.wrapper {position:absolute;left:-200px;width:300px;height:400px;}
#panel {background:red;position:absolute;right:0;top:30px;width:100px;height:150px;cursor:pointer}
.wrapper > p {background:#000;color:#fff;width:200px;height:400px;}

jQuery:

var isOpen = false;
$('#panel').click(function() {
    if (isOpen) {
        $(this).parent().stop(true, true).animate({left: '-200'}, 'fast');
    } else {
        $(this).parent().stop(true, true).animate({left: '0'}, 'fast');
    }
    isOpen = !isOpen;
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜