Connecting Tech Pros Worldwide Forums | Help | Site Map

Simple animation with javascript - IE causes problems

Newbie
 
Join Date: Feb 2008
Posts: 4
#1: Mar 29 '08
Hey guys!

I'm currently working on project, in which I need to animate a menu. It seems to work all right in Safari and Firefox, but Internet Explorer 7.0 makes the animation run slower, and I can't figure out why!?
So far I have only tested it in version 7.0 of Internet Explorer.

First of all I'll show you the Javascript code, which runs in a seperate document:

Expand|Select|Wrap|Line Numbers
  1. function startSliders(){
  2.  
  3.  
  4.             document.getElementById("menuPunktEt").onclick = function(){
  5.                 if (mayI == true) {
  6.                     if (rightSide == 4) {
  7.                     }
  8.                     else 
  9.                         if (rightSide == 3) {
  10.                             rightSide = 4;
  11.                             leftSide = 0;
  12.                             animate('contentEt', 'contentTo');
  13.                         }
  14.                     if (rightSide == 2) {
  15.                         rightSide = 4;
  16.                         leftSide = 0;
  17.                         animate('contentEt', 'contentTre');
  18.                     }
  19.                     if (rightSide == 1) {
  20.                         rightSide = 4;
  21.                         leftSide = 0;
  22.                         animate('contentEt', 'contentFire');
  23.                     }
  24.                     if (rightSide == 0) {
  25.                         rightSide = 4;
  26.                         leftSide = 0;
  27.                         animate('contentEt', 'forside');
  28.                     }
  29.                 }
  30.             }
  31.             document.getElementById("menuPunktTo").onclick = function(){
  32.                 if (mayI == true) {
  33.                     if (rightSide == 4) {
  34.                         rightSide = 3;
  35.                         leftSide = 1;
  36.                         animate('contentTo', 'contentEt');
  37.                     }
  38.                     else 
  39.                         if (rightSide == 3) {
  40.                         }
  41.                         else 
  42.                             if (rightSide == 2) {
  43.                                 rightSide = 3;
  44.                                 leftSide = 1;
  45.                                 animate('contentTo', 'contentTre');
  46.                             }
  47.                             else 
  48.                                 if (rightSide == 1) {
  49.                                     rightSide = 3;
  50.                                     leftSide = 1;
  51.                                     animate('contentTo', 'contentFire');
  52.                                 }
  53.                                 else 
  54.                                     if (rightSide == 0) {
  55.                                         rightSide = 3;
  56.                                         leftSide = 1;
  57.                                         animate('contentTo', 'forside');
  58.                                     }
  59.                 }
  60.             }
  61.             document.getElementById("menuPunktTre").onclick = function(){
  62.                 if (mayI == true) {
  63.                     if (rightSide == 4) {
  64.                         rightSide = 2;
  65.                         leftSide = 2;
  66.                         animate('contentTre', 'contentEt');
  67.                     }
  68.                     else 
  69.                         if (rightSide == 3) {
  70.                             rightSide = 2;
  71.                             leftSide = 2;
  72.                             animate('contentTre', 'contentTo');
  73.                         }
  74.                         else 
  75.                             if (rightSide == 2) {
  76.                             }
  77.                             else 
  78.                                 if (rightSide == 1) {
  79.                                     rightSide = 2;
  80.                                     leftSide = 2;
  81.                                     animate('contentTre', 'contentFire');
  82.                                 }
  83.                                 else 
  84.                                     if (rightSide == 0) {
  85.                                         rightSide = 2;
  86.                                         leftSide = 2;
  87.                                         animate('contentTre', 'forside');
  88.                                     }
  89.                 }
  90.             }
  91.             document.getElementById("menuPunktFire").onclick = function(){
  92.                 if (mayI == true) {
  93.                     if (rightSide == 4) {
  94.                         rightSide = 1;
  95.                         leftSide = 3;
  96.                         animate('contentFire', 'contentEt');
  97.                     }
  98.                     else 
  99.                         if (rightSide == 3) {
  100.                             rightSide = 1;
  101.                             leftSide = 3;
  102.                             animate('contentFire', 'contentTo');
  103.                         }
  104.                         else 
  105.                             if (rightSide == 2) {
  106.                                 rightSide = 1;
  107.                                 leftSide = 3;
  108.                                 animate('contentFire', 'contentTre');
  109.                             }
  110.                             else 
  111.                                 if (rightSide == 1) {
  112.                                 }
  113.                                 else 
  114.                                     if (rightSide == 0) {
  115.                                         rightSide = 1;
  116.                                         leftSide = 3;
  117.                                         animate('contentFire', 'forside');
  118.                                     }
  119.                 }
  120.             }
  121.         }
  122.  
  123.         function animate(expander, smaller){
  124.             mayI = false;
  125.             bigWindow = expander;
  126.             var slider = document.getElementById(expander);
  127.             var collapse = document.getElementById(smaller);
  128.  
  129.             collapse.style.width = xMinus + "px";
  130.  
  131.             slider.style.width = x + "px";
  132.  
  133.             x += speed;
  134.             xMinus -= speed;
  135.             percent = (lenght - x) / howFar;
  136.             speed = speed * percent;
  137.  
  138.             if (speed > 0.01) {
  139.                 var callFunc = "animate('" + expander + "','" + smaller + "')";
  140.                 setTimeout(callFunc, 1);
  141.             }
  142.             else {
  143.                 mayI = true;
  144.                 x = 0;
  145.                 xMinus = 694;
  146.                 speed = 30;
  147.                 lenght = 8260;
  148.                 howFar = lenght - x;
  149.                 percent = 0;
  150.  
  151.             }
  152.         }
  153.  

And here comes the html-code:


[HTML]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Hummel - You've got game</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<script type="text/javascript" src="jscript.js"></script>
<script type="text/javascript">
var x = 0,xMinus = 695,speed = 30,lenght = 8260,howFar = lenght-x,percent,small,rightSide = 0,leftSide = 4,mayI = true;
window.onload = function() {
startSliders();}
</script>
</head>
<body>
<div id="wrapper">
<div id="shadowTop"></div>
<div id="shadowLeft"></div>
<div id="content">
<div id="contentEt"></div>
<div id="menuPunktEt"></div>
<div id="contentTo"></div>
<div id="menuPunktTo"></div>
<div id="contentTre"></div>
<div id="menuPunktTre"></div>
<div id="contentFire"></div>
<div id="menuPunktFire"></div>
<div id="forside"></div>

</div>
<div id="shadowRight"></div>
<div id="footer"><p class="whiteText">Copyright by J I, M N & N B</p></div>
</div>
</body>
</html>[/HTML]

acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#2: Apr 1 '08

re: Simple animation with javascript - IE causes problems


The memory leak is probably caused by a circular reference. See if this link helps.
Reply