Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery .slideRight effect

Tags:

I need for a div tag to slide out on the right side of the screen, how do I get this effect with jQuery? I've been looking here: http://api.jquery.com/category/effects/sliding/ and it doesn't seem to be what I'm looking for...

like image 989
Webnet Avatar asked Nov 19 '10 21:11

Webnet


People also ask

How to slide right in jQuery?

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.

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

The task here is to create a slide left and right toggle effect in the JQuery, you can use the jQuery animate() method. . animate() method: It is used to change the CSS property to create the animated effect for the selected element.

How to slide image left to right in jQuery?

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

How to use slideUp and slideDown in jQuery?

The jQuery slideToggle() method toggles between the slideDown() and slideUp() methods. If the elements have been slid down, slideToggle() will slide them up. If the elements have been slid up, slideToggle() will slide them down. $(selector).


2 Answers

If you're willing to include the jQuery UI library, in addition to jQuery itself, then you can simply use hide(), with additional arguments, as follows:

$(document).ready(     function(){         $('#slider').click(             function(){                 $(this).hide('slide',{direction:'right'},1000);              });     }); 

JS Fiddle demo.


Without using jQuery UI, you could achieve your aim just using animate():

$(document).ready(     function(){         $('#slider').click(             function(){                 $(this)                     .animate(                         {                             'margin-left':'1000px'                             // to move it towards the right and, probably, off-screen.                         },1000,                         function(){                             $(this).slideUp('fast');                             // once it's finished moving to the right, just                              // removes the the element from the display, you could use                             // `remove()` instead, or whatever.                         }                         );              });     }); 

JS Fiddle demo

If you do choose to use jQuery UI, then I'd recommend linking to the Google-hosted code, at: https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/jquery-ui.min.js

like image 173
David Thomas Avatar answered Feb 02 '23 05:02

David Thomas


Another solution is by using .animate() and appropriate CSS.

e.g.

   $('#mydiv').animate({ marginLeft: "100%"} , 4000); 

JS Fiddle

like image 42
charisis Avatar answered Feb 02 '23 06:02

charisis