1

I have the following jQuery code snippet:

var target1 = $('.div1');
var target2 = $('.div2');
target1.delay(1500).fadeIn();
target2.delay(3000).fadeIn();
// I want to use slide left here instead of .fadeIn()

Similar to .fadeIn() is there a slide left/right option?

I also found this but I'm not sure how to implement it or if it's the right one.

Community
  • 1
  • 1
starbucks
  • 2,926
  • 9
  • 41
  • 53

3 Answers3

3

Use the code from the link you posted.

Include the needed libraries (or use local copies):

<script src="http://code.jquery.com/jquery-latest.js"></script>
<script src="http://jquery-ui.googlecode.com/svn/tags/latest/ui/jquery.effects.core.js"></script>
<script src="http://jquery-ui.googlecode.com/svn/tags/latest/ui/jquery.effects.slide.js"></script>

Add this Javascript to your page:

jQuery.fn.extend({
  slideRightShow: function(speed) {
    return this.each(function() {
        $(this).show('slide', {direction: 'right'}, +speed || 1000);
    });
  },
  slideLeftHide: function(speed) {
    return this.each(function() {
      $(this).hide('slide', {direction: 'left'}, +speed || 1000);
    });
  },
  slideRightHide: function(speed) {
    return this.each(function() {
      $(this).hide('slide', {direction: 'right'}, +speed || 1000);
    });
  },
  slideLeftShow: function(speed) {
    return this.each(function() {
      $(this).show('slide', {direction: 'left'}, +speed || 1000);
    });
  }
});

I even added the speed parameter so that you can specify how fast you want it to animate.

And from then on, you can use something like this:

$("#element_id").slideRightShow();

DEMO: http://jsfiddle.net/EzP2q/1/

Ian
  • 50,146
  • 13
  • 101
  • 111
  • Thanks @ian i tried using the solution above but it won't work. I get the following error: ReferenceError: Query is not defined Query.fn.extend({ – starbucks Apr 25 '13 at 15:10
  • I changed it by adding JQuery and it still gives me the same error but this time with JQuery rather than Query. – starbucks Apr 25 '13 at 15:14
  • @user2184056 You didn't include the jQuery libraries like I said (the first thing in my answer). I updated my answer with a DEMO at the end, which works for me. I even changed the code so that you can specify how fast, if you wanted. – Ian Apr 25 '13 at 15:22
  • @ian i am using your code above and I am stuck. How can i show test sentence by default and instead of the click button i want to add a next and previous button and use it display different slides. Any help? I posted a question here: http://stackoverflow.com/questions/17644018/how-do-i-make-this-jquery-slider-render-slides-properly – KPO Jul 14 '13 at 22:11
2

Here, check this out! This is what you need!

This tut explains everything you need -> Slide Elements in Different Directions

Chamara Keragala
  • 5,627
  • 10
  • 40
  • 58
1

jQuery UI has a slide function

Check out the docs

Matt Busche
  • 14,216
  • 5
  • 36
  • 61