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 720253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:44:14+00:00 2026-05-14T05:44:14+00:00

I am trying to create sliding images effect: Online demo link text . The

  • 0

I am trying to create sliding images effect:
Online demolink text.

The problem is when you click rapidly and randomly on the buttons and not wait for animation to finish causing unpredicted results and even stopping the functionality to work. (and once it stopped in the middle of 2 images…)

How Can I make it work without bugs?
I know that there are some other tools for that sliding like jquery and other approaches like changing the position attribute and not the scrollLeft attribute.
But I want to do it as it is, with scrollLeft, if it possible of course.

The Code:

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
        <title>Untitled Document</title>
        <style type="text/css">
            body
            {
                padding:0px;
                margin:0px;
            }
            #imageContainer
            { 
                width: 500px;
                position: relative;             
            }
            #div
             {              
                overflow: hidden;
                white-space: nowrap;                            
            }

            #div img {
                cursor: pointer;
                vertical-align: bottom;
                width: 500px;
                padding:0px;
                margin:0px;
                display:inline;
            }


        </style>
        <script type="text/javascript">                        
            var scrollIntervalID;
            var currentIndex=0;                                

            function Scroll(ind){

                var dir = ind ==currentIndex?0:ind<currentIndex?-1:1;
                var steps = Math.abs(ind-currentIndex);

                scrollIntervalID = setInterval(function(){
                    var i=(steps*10)-1;
                    return function(){
                        if (i <= 0) 
                            clearInterval(scrollIntervalID);
                        var elm = document.getElementById("div");                   
                        elm.scrollLeft +=dir * 50;
                        i--;   

                        document.getElementById("span").innerHTML=elm.scrollLeft;

                    }
                }(), 15);
                currentIndex=ind;
            }            

        </script>
    </head>
    <body>
        <div id="imageContainer">
            <div id="div">
                <img id="image1" src="Images/pic1.jpg" width="500px"/><img id="image2" src="Images/pic2.jpg" width="500px"/><img id="image3" src="Images/pic3.jpg" width="500px"/><img id="image4" src="Images/pic4.jpg" width="500px"/>
            </div>          
        </div>

        <div>
            <input type="button" value="1" onclick="Scroll(0);"/>
            <input type="button" value="2" onclick="Scroll(1);"/>
            <input type="button" value="3" onclick="Scroll(2);"/>
            <input type="button" value="4" onclick="Scroll(3);"/>
        </div>
        <span id="span"></span>
    </body>
</html>
  • 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-14T05:44:14+00:00Added an answer on May 14, 2026 at 5:44 am

    I would sriously recommend you to use frameworks like jQuery but if you insist to work on the current version, you have to take care of scenarios which happens during the animation.

    You have scrollIntervalID, but it is not used outside the scope of the function. You can try clearing the interval timer by using clearInterval when a previous sliding animation is in progress and advance the position to the intended one before performing the next animation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a sliding menu effect when a link is clicked,
I'm trying to create a sliding horizontal menu with different categories. I would like
I am trying create the image enlargement effect when you hover your mouse over
I'm trying to create a sliding checkbox like the one on the iphone. I
I am trying to create a slide transition effect like the one posted in
I'm trying to create my own loadbar; It consists of 5 bars, sliding in
I'm trying to create a sliding FAQ menu using jQuery, but I'm getting an
I'm trying create a text area in a div with the id of "body".
Ok so I'm trying to create a vertical sliding and I got one to
I am trying create a WCF service that leverages the WPF MediaPlayer on the

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.