Forum Moderators: open

Message Too Old, No Replies

script working in IE not in Firefox

Postioning script is workingin IE but can't find code to make it work in Fi

         

bitstomper

6:51 pm on Oct 6, 2005 (gmt 0)

10+ Year Member



Hi there,

I used to use a complex javascript to move a menu to a position on the page while scroling so menu would stay visible. However, I found the load time for this script too long. I am now trying a simpler script that instead of dropping the menu down to a postion (which creates nice (or annoying) animation) fixes the menu to a position. It works fine for IE, but not for Firefox and Safari as the menu just sits on top of the page, but doesn't 'float' so when scrolling it dissapears with the images on top of the page.

Here is the code:

<SCRIPT LANGUAGE="JavaScript">

function setVariables() {
if (navigator.appName == "Netscape") {
v=".top=";
dS="document.";
sD="";
y="window.pageYOffset";
}
else {
v=".pixelTop=";
dS="";
sD=".style";
y="document.body.scrollTop";
}
}
function checkLocation() {
object="object1";
yy=eval(y);
eval(dS+object+sD+v+yy);
setTimeout("checkLocation()",10);
}

</script>

I have been looking around for hours to find a code that works, but without success. I hope someone here can give me a clue.

Also: are there any lists available of js code with several alternatives for every browser?
Thanks heaps.

RonPK

12:02 pm on Oct 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello bitstomper, welcome to WebmasterWorld!

Firefox and Safari both support the CSS property 'position: fixed'. So if you simply add something like

div#myMenu {position: fixed;}

.. to your CSS, the menu will do what you want.

IE does not and form what I hear will not support 'fixed', so you'll still need the script for that browser.

bitstomper

10:07 pm on Oct 8, 2005 (gmt 0)

10+ Year Member



Thanks Ron,

Your CSS indeed works, however I already have the following code in place:

<div id="object1" style="position:absolute; visibility:show; left:0px; top:0px; z-index:2">

This works in IE, but won't work if I set the postion property to fixed. Should I create two sets of code, one for IE and one for the others?

bitstomper

10:09 pm on Oct 8, 2005 (gmt 0)

10+ Year Member



I also have the problem that on MouseOver and on MouseOut do not work anymore. This code is part of the <table> following the previous <div> tag.

RonPK

2:32 pm on Oct 9, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Maybe the code in post #2 in this thread [webmasterworld.com] can be of use.

bitstomper

11:35 am on Oct 11, 2005 (gmt 0)

10+ Year Member



Ron, you are a champ!

I have been looking for simple code for ages.
The code I used to use had so many extra 'features' on it it took too long to load. The images now stick in all browsers.

Can I bother you with one more query?

Now the images (which are links and part of the navigation of the site) do not show rollover images any more and in IE the cursor does not change to a hand when hovering over the image.

So basically on MouseOver and On MouseOut do not work.
This code is part of the <div>

RonPK

4:39 pm on Oct 12, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sounds like your fixed div is covered by some other, transparent element. You could try raising the z-index of the fixed div to, let's say, 100?

bitstomper

2:40 am on Oct 13, 2005 (gmt 0)

10+ Year Member



Tried that, but no success on any browser.
Could you please help me further as this has to work otherwise the whole thing has been useless. Here is the code:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style type="text/css">
#theDiv {position: fixed; left: 5px; top: 0px; Z-Index:100; cursor:hand }
</style>
<!--[if IE ]>
<style type="text/css">
#theDiv {position: absolute; Z-Index:100; cursor:hand}
</style>
<![endif]-->
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Untitled Document</title>

</head>

<body background="Images/backgr.jpg" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">

<script language="JScript">
if (document.recalc && document.body.attachEvent) {
theDiv.style.setExpression("top", "document.body.scrollTop + 150");
document.body.onscroll=function(){document.recalc(true)};
}
</script>
<div id="theDiv">
<table border="0" width="118" cellspacing="5" cellpadding="0">

<tr>
<td><br><br><br><br><br><br><br>
<p align="center"><a onMouseOver="changeImages( /*CMP*/'FAQbutton1',/*URL*/'Images/FAQbutton2.gif');return true" onMouseOut="changeImages( /*CMP*/'FAQbutton1',/*URL*/'Images/FAQbutton1.gif');return true" href="FAQ.html"><img src="Images/FAQbutton1.gif" alt="" name="FAQbutton1" height="25" width="118" border="0"></a>
</td></tr>

</table>
</div>

There is more in the table, but all just repetitions of the same above.

Outside this div tag on the bottom of the page there is another linked image. This one does show a hand when hovering, but there too no change of the image.

Cursor does change to hand in FireFox, but still no rollovers.

Thank you

RonPK

8:48 am on Oct 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The script can only run if the div exists. So the order in the document has to be

<div id="theDiv">
bla
</div>
<script>
bla
</script>

Otherwise, it will throw an error and not execute any other scripts - like the mouseover handler.

bitstomper

9:19 am on Oct 13, 2005 (gmt 0)

10+ Year Member



Sorry for my stupidity Ron.
Thanks for that.

Except it does not change anything. Still no hand cursor in IE and no MouseOver changes in any browsers.

Maybe you could try to run it and see if it works for you with your images?

Thanks again,

bitstomper

10:38 am on Oct 13, 2005 (gmt 0)

10+ Year Member



Doh!
I noticed there was a Javascript code missing defining the onmouseover and onmouseout functions.

After I added that it all works except for IE for Mac version 5.2.
It works on IE (Windows version) Firefox and Safari.

Any clue what I can do to makeit work in IE for Mac?

Thanks

Bernard Marx

12:45 pm on Oct 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I've heard whispers that IE5 Mac supports position:fixed; so you could try excluding mac from the conditionals. How that's done without hackery, I don't know.

Personally, when using a site, although I find fixed position menus are really helpful, I find stupid, quivering, scripted ones more distracting than they are worthwhile. There are a good few position fixed CSS emulations about for IE5+. You might find them interesting.

Start here [tagsoup.com]
or here [cssplay.co.uk].

RonPK

5:17 pm on Oct 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> Start [u]here[/u]

Now why didn't I think of that one? I've even actually met the author, IRL... Thx, Bernard.

bitstomper

10:48 pm on Oct 13, 2005 (gmt 0)

10+ Year Member



Thanx everyone for contributing to the solution.
At this stage the solution of Bernard is too complicated for me as I am only a beginner at this.

Even thouigh I would like the script to include all browsers, I might leave it at this as the menu still works, but w/o rollovers in IE 5 for Mac.