2 Replies - 2125 Views - Last Post: 10 November 2012 - 09:46 PM

#1 tim9009  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 73
  • Joined: 01-October 10

Moving divs with javascript?

Posted 09 November 2012 - 01:13 PM

Hello

I have been working on some code to move a div up and down (like a pop-up window entering and leaving the screen) that will work dynamicly on any web site. The problem is that I just can't get the div to move! It just simply disapears. I know all my loops and what not are working and that it is the code to actually move the div that is failing. Here is a small portion of my javascript code:

function dropdownWindowAnimationUp(window, counter)
{
    console.log("In dropdownWindowAnimationUp");
    counter = counter + 1;
    windowObj = document.getElementById(window);
    
    windowObj.style.top = parseInt(windowObj.style.top) + 1 + 'px';
    
    if(counter >= 100)
    {
        clearTimeout(animation_timer);
        return;
    }
    
    animation_timer = setTimeout(dropdownWindowAnimationUp(window, counter), 30);
}


Could you please have a quick look and show me what I am doing wrong?

Thank you!
-Tim

Is This A Good Question/Topic? 0
  • +

Replies To: Moving divs with javascript?

#2 tim9009  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 73
  • Joined: 01-October 10

Re: Moving divs with javascript?

Posted 10 November 2012 - 10:25 AM

Also: If I console.log() the value of windowObj.style.top I see that the function is behaving as expected in that area. I also removed the code I had that hid the div. I then see that every thing is working except the div actually moving. Don't know if this will make it easyer for you to figure this out.

Thank you!
-Tim
Was This Post Helpful? 0
  • +
  • -

#3 tim9009  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 73
  • Joined: 01-October 10

Re: Moving divs with javascript?

Posted 10 November 2012 - 09:46 PM

I fixed it. I had to use the windowObj.offsetTop to get the current CSS top value, and then I had to use the windowObj.style.top to set the value. (I also set the CSS class to position: absolute;.)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1