The slideDown() method is used to slide down a hidden HTML element. You can add a speed parameter fast, slow or milliseconds to specify the speed of sliding down the element.
This example slides down a hidden image.
<!DOCTYPE html> <html> <head> <script> $("#btn1").click(function(){ $("#twin1").slideDown("slow"); }); }); </script> </head> <body> <button id="btn1">Click to slide down in the hidden image</button><br> <img id="twin1" src="twin.jpg" style="display:none; width:50%; height:auto"> </body> </html>
The slideUp() method is used to slide up an element. You can add the speed parameter fast, slow or milliseconds to specify the sliding speed.
<!DOCTYPE html> <html> <head> <script> $(document).ready(function(){ $("#btn2").click(function(){ $("#twin2").slideUp(3000); }); }); </script> </head> <body> <button id="btn2">Click to slide up the image</button><br> <img id="twin2" src="twin.jpg" style="width:50%; height:auto"> </body> </html>
The jQuery slideToggle() method toggles between the slideDown() and the slideUp() methods. You can add speed parameter 'slow', 'fast' or milliseconds to specify the sliding speed
<!DOCTYPE html> <html> <head> <script> $(document).ready(function(){ $("#btn3").click(function(){ $("#twin3").slideToggle(4000); }); }); </script> </head> <body> <button id="btn3">Click to slide down and slide up the image</button><br> <img id="twin3" src="twin.jpg" style="display:none; width:50%; height:auto"> </body> </html>
You can use the stop() method to stop the sliding action. In fact, it is be used to kill any jQuery animation.
<!DOCTYPE html> <html> <head> <script> $(document).ready(function(){ $("#btn4").click(function(){ $("#twin4").slideUp(4000); }); $("#btn5").click(function(){ $("#twin4").stop(); }); }); </script> </head> <body> <button id="btn4">Click to slide up the image</button> <button id="btn5">Click to stop sliding</button><br> <img id="twin5" src="twin.jpg" style="display:none; width:50%; height:auto"> </body> </html>
Copyright©2008 Dr.Liew Voon Kiong. All rights reserved |Contact|Privacy Policy