Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Slide div left/right using jQuery

Tags:

jquery

I found following code in multiple places to slide left/right:

$('#hello').hide('slide', {direction: 'left'}, 1000); 

However, i can't get it working. Here is minimalistic test which I am trying:

<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en-us"> <head>     <script src="http://code.jquery.com/jquery-latest.js"></script>     <script>     $(document).ready(function() {         $("#test").click(function() {             $('#hello').hide('slide', {direction: 'left'}, 1000);         });     });    </script> </head> <body>     <article >         <div id="hello">             Hello                </div>         <p><span id="test">Test</span>     </arcticle> </body> 

I tried it in Chrome and Safari and it doesn't work.

What is the problem? Are there other working methods to slide left/right?

like image 241
Victor Ronin Avatar asked Feb 12 '13 00:02

Victor Ronin


People also ask

How to make div slide from left to right in jQuery?

hide("slide", { direction: "right" }, 500, function () { $('#fsEditWindow'). show("slide", { direction: "left" }, 500); }); });

How to slide image left to right in jQuery?

$('image'). show("slide", { direction: "right" }, 1200);

How do you create a left and right toggle effect in jQuery slide?

Answer: Use the jQuery animate() method There are no such method in jQuery like slideLeft() and slideRight() similar to slideUp() and slideDown() , but you can simulate these effects using the jQuery animate() method.


1 Answers

You can easy get that effect without using jQueryUI, for example:

$(document).ready(function(){     $('#slide').click(function(){     var hidden = $('.hidden');     if (hidden.hasClass('visible')){         hidden.animate({"left":"-1000px"}, "slow").removeClass('visible');     } else {         hidden.animate({"left":"0px"}, "slow").addClass('visible');     }     }); }); 

Try this working Fiddle:

http://jsfiddle.net/ZQTFq/

like image 181
Marcos Besteiro López Avatar answered Sep 30 '22 03:09

Marcos Besteiro López