Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  • Thread Tools
  • Rate This Thread
  1. #1
    New to the CF scene
    Join Date
    Feb 2016
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Recursive jquery functions

    Hi everybody!

    I try to make a slider, but i can't understand how jquery recursive functions work. Here is the code so far:

    Code:
    (function ($) {
    
        var w = 160;
    
        $.fn.moveLeft = function (elm, delay, x, y, t) {
            var elm_s = $(elm);
            $.each(elm_s, function () {
                $(this).delay(delay).animate({left: '-=' + w}, t);
            });
        };
    
        $.fn.moveRight = function (elm, delay, x, y, t) {
            var elm_s = $(elm);
            $.each(elm_s, function () {
                $(this).delay(delay).animate({left: '+=' + w}, t);
            });
        };
    
        $.fn.banner = function(){
            //first text blocks in
            $(this).moveLeft('#text_wrap h2', 800,0,0,1000);
            $(this).moveRight('#text_wrap h3', 800,0,0,1000);
    
            //first text blocks out
            $(this).moveLeft('#text_wrap h2', 3000,0,0,600);
            $(this).moveRight('#text_wrap h3', 3000,0,0,600);
    
            //second img  in
            $(this).moveRight('#second-img', 5400,0,0,1000);
    
        };
    
    }(jQuery));
    
    $(document).ready(function () {
    
        $(this).banner();
    
    });
    I tried to add $(this).banner(); after the last moveRight() but if i do that after a long delay all the functions run at once. Can somebody show me the way?

  2. #2
    New Coder
    Join Date
    Feb 2016
    Posts
    80
    Thanks
    0
    Thanked 16 Times in 16 Posts
    What do you intend to slide? Text or images? Please post the HTML. Without having analyzed your code completely I assume that you have to place the recursive call as a callback function of your animate().
    Last edited by Sempervivum; 03-18-2016 at 06:55 PM.


 

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •