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
The code I have is listed below:
Any help would be much appreciated
Thanks
David
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:
Code:
var target_x = 10;
var target_y = 10;
var has_inner = typeof(window.innerWidth) == 'number';
var has_element = document.documentElement && document.documentElement.clientWidth;
var fm_id='floatdiv';
var floating_menu = document.getElementById ? document.getElementById(fm_id) : document.all ? document.all[fm_id] : document.layers[fm_id];
var fm_shift_x, fm_shift_y, fm_next_x, fm_next_y;
//------------------FUNCTION START---------------------------
function move_menu()
{
alert('line 28');
if (document.layers)
{
alert('line 31');
floating_menu.left = fm_next_x;
floating_menu.top = fm_next_y;
}
else
alert('line 36');
{
floating_menu.style.left = fm_next_x + 'px';
floating_menu.style.top = fm_next_y + 'px';
}
}
//------------------FUNCTION END-----------------------------
//------------------FUNCTION START---------------------------
function compute_shifts()
{
alert('compute_shifts');
alert('line 43');
fm_shift_x = has_inner ? pageXOffset : has_element ? document.documentElement.scrollLeft : document.body.scrollLeft;
if (target_x < 0)
alert('line 46');
fm_shift_x += has_inner ? window.innerWidth : has_element ? document.documentElement.clientWidth : document.body.clientWidth;
fm_shift_y = has_inner ? pageYOffset : has_element ? document.documentElement.scrollTop : document.body.scrollTop;
if (target_y < 0)
alert('line 50');
fm_shift_y += has_inner ? window.innerHeight : has_element ? document.documentElement.clientHeight : document.body.clientHeight;
}
//------------------FUNCTION END-----------------------------
//------------------FUNCTION START---------------------------
function float_menu()
{
alert('float_menu');
var step_x, step_y;
alert('line 61');
compute_shifts();
alert('line 64');
step_x = (fm_shift_x + target_x - fm_next_x) * .07;
if (Math.abs(step_x) < .5)
step_x = fm_shift_x + target_x - fm_next_x;
step_y = (fm_shift_y + target_y - fm_next_y) * .07;
if (Math.abs(step_y) < .5)
step_y = fm_shift_y + target_y - fm_next_y;
if (Math.abs(step_x) > 0 ||
Math.abs(step_y) > 0)
{
fm_next_x += step_x;
fm_next_y += step_y;
move_menu();
}
setTimeout('float_menu()', 20);
}
alert('line 85');
compute_shifts();
if (document.layers)
{
// Netscape 4 cannot perform init move
// when the page loads.
alert('line 92');
fm_next_x = 0;
fm_next_y = 0;
}
else
{
alert('line 98');
fm_next_x = fm_shift_x + target_x;
fm_next_y = fm_shift_y + target_y;
move_menu();
}
//float_menu();
window.onload = float_menu();
Thanks
David
Comment