Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-03-2011, 01:31 PM   PM User | #1
nadazoulou
New Coder

 
Join Date: Aug 2011
Location: Mauritius
Posts: 14
Thanks: 2
Thanked 0 Times in 0 Posts
nadazoulou is an unknown quantity at this point
Add condition to Animate function

Hi all , im a newbie to jquery and tried hard to write bits of code...My problem is I have a panel with absolute position left set to 0 in default and I want to hide in by sliding it to the left..so as used the animate funstion lije this:


<script type="text/javascript">
$(document).ready(function() {

$("#panel-tab").click(function(e) {

e.preventDefault();
$("#panel").animate({"left":"-856px"}, "slow");

});
});
</script>

MY CSS:
#panel {
width: 864px;
height: 369px;
position: absolute;
top: 195px;
left: 0px;
z-index: 200;
background:url('../images/bg_panel.png') no-repeat;
padding:20px 0 0 18px;
text-align:left;
}
#panel-tab {
width: 21px;
height: 371px;
position: absolute;
top: 9px;
left: 856px;
background:url(../images/panel-arrw-show.png) no-repeat;
text-decoration: none;
color: #FFFFFF;
text-indent:-999999px;
}




It work well but not I must figured out how to make a check or if statement to bring back the panel to default position when clicked again.

Any help on how to do that please?

//Sam
nadazoulou is offline   Reply With Quote
Old 11-03-2011, 02:14 PM   PM User | #2
SB65
Senior Coder

 
Join Date: Feb 2009
Location: West Yorkshire
Posts: 2,817
Thanks: 9
Thanked 681 Times in 675 Posts
SB65 will become famous soon enoughSB65 will become famous soon enough
I'd do it like this:

Code:
$("#panel-tab").click(function(e) {

e.preventDefault();
if($('#panel').hasClass('hidden'))//it's already hidden
{
$("#panel").animate({"left":0}, "slow").removeClass('hidden');//move it to the right and remove the hidden class
}
else $("#panel").animate({"left":"-856px"}, "slow").addClass('hidden');//it's not hidden so hide it and add the hidden class

});
});
SB65 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:59 AM.


Advertisement
Log in to turn off these ads.