JavaScript animation very buggy

Chucksef

So I have a very small, insignificant site i'm working on. my website If you click on the grey-ish bar at the bottom, it will animate a sort of eased-in for me to use in the future to edit info i put together on various pictures or whatever i decide i want to put up there.

my code for the animation is: (edited to reflect changes)

function animateForm(startPosition,endPosition,firstKey,keyInterval) 
{
    if(currentKey != lastKey)
    {
        animationPointer =( .5 * Math.sin((currentKey * (Math.PI/totalKeys)) - (Math.PI/2))) + .5;
        currentPosition = (animationPointer)*endPosition;
        bottomForm.style.bottom = currentPosition + "px";
        currentKey=currentKey+(keyInterval*1);
    }
    else 
    {
        clearInterval(int);
        int=0;
    }
}

SOLVED! The problem was that I was multiplying the "animation pointer" (a decimal from 0 to 1 indicating the progress in the animation) by the "end position," and if the animation was aiming for an end position of "0," This set my form's position immediately to the "hide" position, and things asploded from there.

What i needed to do multiply the pointer by the maximum height the form could reach so that on its descent it could gradually return a smaller and smaller value to the "currentPosition" variable.

user2437417

You're never clearing the setInterval between animations. Simply typing clearInterval; doesn't do anything. You need to store the ID that's returned from setInterval(), and then pass it to a call to clearInterval();.

Because you're not clearing, those original intervals are still running and still trying to operate on the same variables.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related