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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:21:00+00:00 2026-05-25T03:21:00+00:00

setInterval in this code doesn’t work properly <script language=javascript> x = y = 0;

  • 0

setInterval in this code doesn’t work properly

<script language="javascript">
    x = y = 0;
    function mvtb(p, g){
        i = 0;
        tmp = setInterval(function (){
            if(i < 100 && i >= 0){
                document.getElementById("plan").scrollTop = 200*(y+((y-g)*(i/100)));
                document.getElementById("plan").scrollLeft = 660*(x+((x-p)*(i/100)));
                i++;
            }
            else if(i == 100){
                clearInterval(tmp);
            }
        }, 10);
        x = p; y = g;
    }
</script>

CSS

<style>
#plan {overflow: hidden; height: 200px; width: 660px; background: #444;}
.plan {width: 1980px;}
.plan table {height: 200px; width: 660px;}
</style>

HTML

<body style="background: black; color: white;">
<center>
<div id="plan">
<table class="plan">
    <tr id="g0">
        <td class="p0"><table bgcolor="gray"><tr><td>0 0</td></tr></table></td>
        <td class="p1"><table bgcolor="blue"><tr><td>1 0</td></tr></table></td>
        <td class="p2"><table bgcolor="yellow"><tr><td>2 0</td></tr></table></td>
    </tr>
    <tr id="g1">
        <td class="p0"><table bgcolor="green"><tr><td>0 1</td></tr></table></td>
        <td class="p1"><table bgcolor="orange"><tr><td>1 1</td></tr></table></td>
        <td class="p2"><table bgcolor="red"><tr><td>2 1</td></tr></table></td>
    </tr>
    <tr id="g2">
        <td class="p0"><table bgcolor="brown"><tr><td>0 2</td></tr></table></td>
        <td class="p1"><table bgcolor="white"><tr><td style="color: black">1 2</td></tr></table></td>
        <td class="p2"><table bgcolor="crimson"><tr><td>2 2</td></tr></table></td>
     </tr>
</table>
</div>
<br /><br /><br />Move Table<br />
<button onClick="mvtb(0, 0);">0 0</button> &nbsp; <button onClick="mvtb(1, 0);">1 0</button> &nbsp; <button onClick="mvtb(2, 0);">2 0</button><br />
<button onClick="mvtb(0, 1);">0 1</button> &nbsp; <button onClick="mvtb(1, 1);">1 1</button> &nbsp; <button onClick="mvtb(2, 1);">2 1</button><br />
<button onClick="mvtb(0, 2);">0 2</button> &nbsp; <button onClick="mvtb(1, 2);">1 2</button> &nbsp; <button onClick="mvtb(2, 2);">2 2</button><br />
</center>
</body>
  • 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-25T03:21:01+00:00Added an answer on May 25, 2026 at 3:21 am

    Try this instead. Only update g and p after the animation is finished and swap the subtraction when calculating the new scrollTop/scrollLeft. You also need to make sure the loop runs 100 times, not 99. JSFiddle

    x = y = 0;
    
    function mvtb(p, g) {
        var i = 1;
        var tmp = setInterval(function() {
            if (i <= 100 ) { 
                document.getElementById("plan").scrollTop = 200 * (y + ((g - y) * (i / 100)));
                document.getElementById("plan").scrollLeft = 660 * (x + ((p - x) * (i / 100)));
                i++;
            }
            else {
                clearInterval(tmp);
                x = p;
                y = g;
            }
        }, 10);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Why doesn't this code work to turn off setInterval? I click an element to
Consider this JavaScript Code: <script type=text/javascript> function loop(Message){ document.getElementById('output').innerHTML = document.getElementById('output').innerHTML + Message +
I've made this code: window.setInterval(function(){ var a = doStuff(); var b = a +
Look at this code var count = 0, count2 = 0 setInterval(function() { //
I have the following code: var focusIntervalObj = setInterval(function(){ focusDelayCaused++; console.log(focusDelayCaused); }, 100); clearInterval(focusIntervalObj);
I am using setInterval(fname, 10000); to call a function every 10 seconds in JavaScript.
p2 = setInterval(function () { clearInterval(p2); some code here; }, waitTime) I need to
I have written a javascript function that uses setInterval to manipulate a string every
In a javascript code I develop, some function should be called every 1 second.
My Code: $(function() { $('a.startSlideshow').click(function() { startSlideShow = window.setInterval(function() { slideSwitch() }, 1000); });

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.