470,591 Members | 2,089 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,591 developers. It's quick & easy.

Floating Menu

I am trying to create a floating menu that moves down the left hand side of the screen. I have some code that works great when it is embedded into the web page. What I would like to do is reference it from an include file.

I can see the include file and I have put alerts through out the code and i can see the following
  • Line 85
    compute_shifts
    Line 43

The code I have is listed below:

Expand|Select|Wrap|Line Numbers
  1. var target_x = 10;
  2. var target_y = 10;
  3.  
  4. var has_inner = typeof(window.innerWidth) == 'number';
  5. var has_element = document.documentElement && document.documentElement.clientWidth;
  6.  
  7. var fm_id='floatdiv';
  8. var floating_menu = document.getElementById ? document.getElementById(fm_id) : document.all ? document.all[fm_id] : document.layers[fm_id];
  9.  
  10. var fm_shift_x, fm_shift_y, fm_next_x, fm_next_y;
  11.  
  12.  
  13.  
  14. //------------------FUNCTION START---------------------------
  15. function move_menu()
  16. {
  17. alert('line 28');
  18.     if (document.layers)
  19.     {
  20. alert('line 31');
  21.         floating_menu.left = fm_next_x;
  22.         floating_menu.top = fm_next_y;
  23.     }
  24.     else
  25. alert('line 36');
  26.     {
  27.         floating_menu.style.left = fm_next_x + 'px';
  28.         floating_menu.style.top = fm_next_y + 'px';
  29.     }
  30. }
  31. //------------------FUNCTION END-----------------------------
  32. //------------------FUNCTION START---------------------------
  33.  
  34. function compute_shifts()
  35. {
  36. alert('compute_shifts');
  37. alert('line 43');
  38.     fm_shift_x = has_inner ? pageXOffset : has_element ? document.documentElement.scrollLeft : document.body.scrollLeft;
  39.     if (target_x < 0)
  40. alert('line 46');
  41.         fm_shift_x += has_inner ? window.innerWidth : has_element ? document.documentElement.clientWidth : document.body.clientWidth;
  42.         fm_shift_y = has_inner ? pageYOffset : has_element ? document.documentElement.scrollTop : document.body.scrollTop;
  43.     if (target_y < 0)
  44. alert('line 50');
  45.         fm_shift_y += has_inner ? window.innerHeight : has_element ? document.documentElement.clientHeight : document.body.clientHeight;
  46. }
  47.  
  48. //------------------FUNCTION END-----------------------------
  49. //------------------FUNCTION START---------------------------
  50.  
  51. function float_menu()
  52. {
  53. alert('float_menu');
  54.     var step_x, step_y;
  55. alert('line 61');
  56.  
  57.     compute_shifts();
  58. alert('line 64');
  59.  
  60.     step_x = (fm_shift_x + target_x - fm_next_x) * .07;
  61.     if (Math.abs(step_x) < .5)
  62.         step_x = fm_shift_x + target_x - fm_next_x;
  63.         step_y = (fm_shift_y + target_y - fm_next_y) * .07;
  64.  
  65.     if (Math.abs(step_y) < .5)
  66.         step_y = fm_shift_y + target_y - fm_next_y;
  67.  
  68.     if (Math.abs(step_x) > 0 ||
  69.         Math.abs(step_y) > 0)
  70.     {
  71.         fm_next_x += step_x;
  72.         fm_next_y += step_y;
  73.         move_menu();
  74.     }
  75.  
  76.     setTimeout('float_menu()', 20);
  77. }
  78.  
  79. alert('line 85');
  80.  
  81. compute_shifts();
  82. if (document.layers)
  83. {
  84.     // Netscape 4 cannot perform init move
  85.     // when the page loads.
  86. alert('line 92');
  87.     fm_next_x = 0;
  88.     fm_next_y = 0;
  89. }
  90. else
  91. {
  92. alert('line 98');
  93.     fm_next_x = fm_shift_x + target_x;
  94.     fm_next_y = fm_shift_y + target_y;
  95.     move_menu();
  96. }
  97.  
  98. //float_menu();
  99.  
  100. window.onload = float_menu();
  101.  
Any help would be much appreciated

Thanks

David
Jul 11 '07 #1
1 1281
acoder
16,027 Expert Mod 8TB
Do you not see any more alerts after that? Do you get any errors?
Jul 12 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

6 posts views Thread by TyBreaker | last post: by
reply views Thread by pat.maher | last post: by
2 posts views Thread by Dariusz TomoŮ | last post: by
4 posts views Thread by Jason Carlton | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.