My problem:
Changing the margin-top property via JavaScript objectName.style.marginTop = value; works well in Chrome and Safari, however in Firefox, the positioning seems to be all wrong. Instead of placing the element over the viewport, subsequently lowering it until it is slightly underneath the desired position and then moving it up a bit, Firefox places it way underneath the final position, moves it up and then down, almost mirroring the desired animation.
If I switch of Javascript and enter the value in CSS, the positioning is alright, so I guess the mistake lies in the .js.
Context:
I am trying to create a simple animated logo via JavaScript. I want it to drop from outside the browser viewport into its position. The logo is the HTML-element <img id="site_logo" src="logo.png" />
Here goes the JavaScript code:
var logoValue = -400;
function onLoad(){
// ...
logoStarter();
}
function logoStarter(){ //sets the logo in its starting position outside the viewport
var site_logo = document.getElementById("site_logo");
site_logo.style.marginTop = logoValue +"px";
logoAnimationDown();
}
function logoAnimationDown(){ // moves the logo down until it is somewhat underneath its final position
if(logoValue <= 20){
console.log(logoValue);
logoValue += 17;
var site_logo = document.getElementById("site_logo");
site_logo.style.marginTop = logoValue +"px";
setTimeout('logoAnimationDown()', 30);
}
else{
setTimeout('logoAnimationUp()', 30);
}
}
function logoAnimationUp(){ // moves the logo up to its final position
if(logoValue > 0){
console.log(logoValue);
logoValue -= 10;
var site_logo = document.getElementById("site_logo");
site_logo.style.marginTop = logoValue + "px";
setTimeout('logoAnimationUp()', 30);
}
}