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

  • SEARCH
  • Home
  • 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 3302272
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:50:04+00:00 2026-05-17T20:50:04+00:00

I have a problem with my site , or at least I think I

  • 0

I have a problem with my site, or at least I think I have. I use a very simple nearly recursive Javascript function to move two pictures. However, on my four year old computer, this is not a smooth movement. I’ve reduced the size of the pictures, but…

The code is not recursive as I use setTimeout between calls.

The code is the following:
(onload)

sImgArray = ["imgLaVera", "imgAlmanzor", "imgRosarito", "imgBaile"];
iImg = sImgArray.length - 1;
setTimeout('playShow(0,' + iImg + ')', 4000);

function playShow(iVisible, iImgs)
{
    if( iVisible < iImgs )
        iLeft = iVisible + 1;
    else
        iLeft = 0;

    imgLeft = document.getElementById(sImgArray[iLeft]);
    imgLeft.style.left = "-" + imgLeft.width + "px";
    playMove(-imgLeft.width, iVisible, iImgs);
}
function playMove(i, iVisible, iImgs)
{
    if( iVisible < iImgs )
        iLeft = iVisible + 1;
    else
        iLeft = 0;

    imgLeft = document.getElementById(sImgArray[iLeft]);
    imgRight = document.getElementById(sImgArray[iVisible]);

    if( i < 0 )
    {
        i = i + 5;
        imgLeft.style.left = (i - 2) + "px";
        imgRight.style.left = (i + imgLeft.width) + "px";
        setTimeout('playMove(' + i + ', ' + iVisible + ',' + iImgs + ')', 75);
    }
    else
    {
        if( iVisible < iImgs )
            iVisible = iVisible + 1;
        else
            iVisible = 0;
        setTimeout('playShow(' + iVisible + ',' + iImgs + ')', 4000)
    }
}

Any suggestions?

  • 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-05-17T20:50:04+00:00Added an answer on May 17, 2026 at 8:50 pm

    The following settings in playMove will give you what you want:

    i = i + 1;
    setTimeout('playMove( ... )', 15);
    

    Your animation seemes sluggish because you’re changing image positions rarely and with big jumps. If you want it to be smoother you should change the positions more frequently but less pixels in each step.

    Old: 5 px / 75 ms
    New: 1 px / 15 ms
    

    Sidenotes

    If you really care for speed, don’t select elements in every call of the rendering function (playMove).
    Do this at the end of showbefore calling setTimeout:

    // select elements by their id and replace them in the array
    for (var i = sImgArray.length; i--;) {
      sImgArray[i] = document.getElementById( sImgArray[i] );
    }
    

    Now you can simply write

    sImgArray[iLeft]
    

    instead of

    document.getElementById(sImgArray[iLeft])
    

    in playMove and playShow.

    Secondly you should try to avoid passing functions as textual parameters because they need to be evaled separately.

    // GOOD
    setTimeout(function() {
        playShow(iVisible, iImgs);
    }, 4000);
    
    // BAD
    setTimeout('playShow(' + iVisible + ',' + iImgs + ')', 4000)
    

    Thirdly this is like the ugliest thing I’ve seen in my life:

    setTimeout('show.call(\'index\');', 6000);
    

    Don’t use the this reference to pass parameter to a function. That’s what normal parameterlist is for.

    setTimeout(function() {
        show('index');
    }, 4000);
    

    Then your function show becomes something like this:

    function show( page ) // pass string as an argument
    {
        if ( page == "index" )
        {
        // ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with my site. I want that the shadow stops at
I have a problem on my site's login page in IE7 browser. One of
I have a problem in a site that I am trying to develop Sometimes
I have a problem with my site. The site has multiple entities: Articles, Posts,
i have this annoying problem with my site where, when you click on a
I have a problem with my search on my site I don't understand why
I have a problem with a oneway web method that open a moss site
I have a problem with Drupal uploads path when in a multi language site.
I have a problem with the FreeTextBox rich Text Editor in my ASP.NET site.
I'm re-designing a Web site and I have a problem with the existing data

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.