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 12-02-2011, 05:11 AM   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 onload event trigger + timer

Hi all i have this script below that slide up and slide down a panel on click :

<script type="text/javascript">

// When the DOM is ready, initialize the scripts.
jQuery(function( $ ){

// Get a reference to the container.
var container = $( "#panel" );


// Bind the link to toggle the slide.
$( ".btn-slide" ).click(
function( event ){
// Prevent the default event.
event.preventDefault();

// Toggle the slide based on its current
// visibility.
if (container.is( ":visible" )){

// Hide - slide up.
container.slideUp( 500 );
$(this).removeClass("active");

} else {

// Show - slide down.
container.slideDown( 500 );
$(this).addClass("active");

}
}
);

});

</script>

What i want to do is also to make the panel slide up on page load...delay for 3 seconds then slide down..

Being a newbie .. I have no idea on how to add this bit of code...

Any help appreciated..

Thks

//Sam
nadazoulou is offline   Reply With Quote
Old 12-02-2011, 05:59 AM   PM User | #2
Amphiluke
Regular Coder

 
Amphiluke's Avatar
 
Join Date: Jul 2009
Posts: 312
Thanks: 3
Thanked 89 Times in 89 Posts
Amphiluke is on a distinguished road
Code:
 $(window).load(function() {
    container.slideUp(500).delay(3000).slideDown(500);
 });
I can't make out though why you want to get such a strange effect…
__________________
I am still learning English
Amphiluke is offline   Reply With Quote
Old 12-02-2011, 06:10 AM   PM User | #3
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
Hi thks for the code...on page load the panel slide up but it doesn't slide down after the 3 seconds delay...

any idea ?
nadazoulou is offline   Reply With Quote
Old 12-02-2011, 06:18 AM   PM User | #4
Amphiluke
Regular Coder

 
Amphiluke's Avatar
 
Join Date: Jul 2009
Posts: 312
Thanks: 3
Thanked 89 Times in 89 Posts
Amphiluke is on a distinguished road
It is strange.
This works correctly for me.
Code:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Noname</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script type="text/javascript">
// When the DOM is ready, initialize the scripts.
 jQuery(function( $ ){

 // Get a reference to the container.
 var container = $( "#panel" );

 $(window).load(function() {
    container.slideUp(500).delay(3000).slideDown(500);
 });

 // Bind the link to toggle the slide.
 $( ".btn-slide" ).click(
 function( event ){
 // Prevent the default event.
 event.preventDefault();

 // Toggle the slide based on its current
 // visibility.
 if (container.is( ":visible" )){

 // Hide - slide up.
 container.slideUp( 500 );
 $(this).removeClass("active");

 } else {

 // Show - slide down.
 container.slideDown( 500 );
 $(this).addClass("active");

 }
 }
 );

 });
</script>
</head>
<body>
<a href="#" class="btn-slide">slide</a>
<div id="panel">ftiogjior</div>

</body>
</html>
__________________
I am still learning English
Amphiluke is offline   Reply With Quote
Users who have thanked Amphiluke for this post:
nadazoulou (12-02-2011)
Old 12-02-2011, 06:43 AM   PM User | #5
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
Ok got it to work..
thks buddy.
nadazoulou 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 05:47 AM.


Advertisement
Log in to turn off these ads.