Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8091085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:56:49+00:00 2026-06-05T19:56:49+00:00

I have the following problem: I am creating a simple plugin jquery carousel, to

  • 0

I have the following problem:
I am creating a simple plugin jquery carousel, to animate images within a box.
But I came across the following problem, using OO to build the plugin, I refer to my object using this.

But one of the functions use the animate method of jquery.
And I want to do this in a recursive way. Because animation is a constant.
But in the callback function jquery animate, this refers to the object animation, and not my object created in the execution of the plugin itself.
How can I call the function callback object in the animation?
I try resolve calling the function run() directly before animation line code, but i get the error:Uncaught RangeError: Maximum call stack size exceeded

if i put the run function in animation callback, i got other error:

this.wraper.animate(
                   {top : '-='+image_height},
                        this.config.speed,
                        this.run()
                   )

or

 this.wraper.animate(
                   {top : '-='+image_height},
                        this.config.speed,
                        function(){
                            this.run();
                        }
                   )

because this is reference to this.wraper object, and not to function object
seems kind of confusing to explain.

Here is the code:

  (function($){

carouselClass = function (el, opts) {
        this.id = $(el).attr("id");        
        this.i = 0;                     
        this.config = opts;
        this.wraper;
        this.count = 0;
        this.flag = true;
        this.init = function() {
            // variables        
            var img = $("#"+this.id).find("img");       
            this.count = img.length;


            //adiciona css necessário a div wrapper
            $("#"+this.id).css("position","relative");
            $("#"+this.id).css("overflow","hidden");


            $("#"+this.id).append("<div></div>");       
            this.wraper = $("#"+this.id).find("div");           


            //definições css da div wrapper
            this.wraper.css("position","absolute");
            this.wraper.css("right","0px");                 
            var direction = this.config.direction;
            var container = this.wraper;
            //adiciona as imagens ao novo container
            img.each(function(){
                if(direction == "left" || direction == "right")
                    $(this).css("float", direction)

                $(this).css("display", "block");
                container.append($(this));                                          
            }); 

            //seta a largura e altura do wraper conforme a direção
            if(direction == "left" || direction == "right")
            {
                this.wraper.width((img.width()*this.count));
                this.wraper.height(img.height());
            }
            else
            {
                this.wraper.height((img.height()*this.count));
                this.wraper.width(img.width());
            }

            this.run(); 
        }           



        this.run = function()
        {                   
            if(this.config.direction == "top")
            {
                height = this.wraper.height();              
                image_height = height/this.count;                   
                for(j = 0; j < (this.count-1); j++)
                {
                    this.wraper.animate(
                        {top : '-='+image_height},
                        this.config.speed

                    )

                }
                this.wraper.animate(
                    {top:'0px'},
                    this.config.speed   
                );
                                    //my problem is this call to function recursive
                this.run();             
            }

            if(this.config.direction == "bottom")
            {
                height = this.wraper.height();              
                image_height = height/this.count;                   
                for(j = 0; j < (this.count-1); j++)
                {
                    this.wraper.animate(
                        {bottom : '-='+image_height},
                        this.config.speed

                    )

                }
                this.wraper.animate(
                    {bottom:'0px'},
                    this.config.speed   
                );
                                    //my problem is this call to function recursive
                this.run();         
            }


            if(this.config.direction == "left")
            {
                width = this.wraper.width();                
                image_width = width/this.count;                 
                for(j = 0; j < (this.count-1); j++)
                {
                    this.wraper.animate(
                        {left : '-='+image_width},
                        this.config.speed

                    )

                }
                this.wraper.animate(
                    {left:'0px'},
                    this.config.speed   
                );
                                    //my problem is this call to function recursive
                this.run();         
            }

            if(this.config.direction == "right")
            {
                width = this.wraper.width();                
                image_width = width/this.count;                 
                for(j = 0; j < (this.count-1); j++)
                {
                    this.wraper.animate(
                        {right : '-='+image_width},
                        this.config.speed

                    )

                }
                this.wraper.animate(
                    {right:'0px'},
                    this.config.speed   
                );
                                    //my problem is this call to function recursive
                this.run();         
            }

        }           
    };

$.fn.carousel = function(options)
{

    var opts = $.extend({}, $.fn.carousel.defaults, options);
    return this.each(function () {
            var instance = new carouselClass($(this), opts);
            /**********Start the carousel ***********/
            instance.init();                
        });

    $.fn.carousel.defaults = {
        'direction': "left",
        'speed': 3000
    };      

}    

 })(jQuery);

if i call in this way, plugin work´s, but only the number of times that I set to i var, and I wish that carousel changing continuously:

this.prepare = function()
        {
            this.i++;

            if(this.i < 3)
            {                   

                    this.run();
            }                           
        }

this.run = function()
        {                   
            if(this.config.direction == "top")
            {
                height = this.wraper.height();              
                image_height = height/this.count;                   
                for(j = 0; j < (this.count-1); j++)
                {
                    this.wraper.animate(
                        {top : '-='+image_height},
                        this.config.speed

                    )

                }
                this.wraper.animate(
                    {top:'0px'},
                    this.config.speed   
                );
                this.prepare();             
            }
                 }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T19:56:52+00:00Added an answer on June 5, 2026 at 7:56 pm
    this.setAnimation=function(state){
            var obj=this;
            if(state)obj.animationID=setInterval(function() { 
                obj.run();
                },obj.config.speed);
            else {
                clearInterval(obj.animationID);
                }
            };
    

    Are you looking for something like this?

    setAnimation(true)//start Animation
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating a simple shop, but have run into a simple problem.. I've got
I have a problem creating the following SQL Statement using LINQ & C# select
maybe that problem is simple, but I have no Idea how to solve this,
I have a pretty simple problem. I'm creating several buttons with a method in
I have following problem: I have built a tabbar application with 4 tabs. I
I have following problem, Code: String a=Yeahh, I have no a idea what's happening
I have the following problem: I have a form in site/banen (currently local running
I have the following problem. I have three classes, A, B and C. A
I have the following problem: I implemented a managed mobile application for Windows Mobile
I have the following problem that the standard library doesn't solve well, and I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.