Forum Moderators: open

Message Too Old, No Replies

crossbrowser .js for positioning.

         

helenp

3:15 pm on Mar 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hi all,
I do know nothing about javascript.
But need an crossbrowser .js to put exact position of an menu that are pure .css with several levels, these are based on hover and I have an .htc file for that.
So the mouseover menu donīt have any javascript at all.

What I want is to have it fixed at left, and tried several things, position fixed with an javascript for IE, but that java force me to use: <!-- //forcing quirks mode: -->, and I canīt use that, I need margin:auto for my site.
So if anybody knows some script for giving it exact position, always on top at left, or any links how to do it myself easily, I would apprecate that.
And that wonīt give an big .js file.
Before had an .js menu, but changed it to this css menu, though it was 35 kbs.

Thanks in advance

helenp

10:48 pm on Mar 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



please, somebody.............
been 3 days trying to use position fixed,
this is my last change.

Purple Martin

11:10 pm on Mar 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sounds like you don't need JavaScript at all. You should be able to do this with CSS. Try asking your question in the CSS forum.

RonPK

11:12 pm on Mar 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



[PM was faster...]

helenp

11:19 pm on Mar 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



no, the menu is pure css,
and there is no way to position it fixed in IE,
I tried them all,
I do have an js script that will position it fixed:
<script type="text/javascript">
function reposicionaMenu(){
document.getElementById("left").style.top = parseInt(document.body.scrollTop + 120) + "px";
}

onload = function(){
if(document.getElementById &&!window.getComputedStyle){// DOM but not Mozilla
document.getElementById("left").style.position = "absolute";
window.onscroll = reposicionaMenu;
}
}
</script>
but to use it I need to use: <!-- //forcing quirks mode: -->

and I cant do that, I need to use margin:auto, wich doesnīt work in quirks mode :)

this is another mode to do without using position fixed: [tierradenomadas.com...]
but that only simply layouts, and the same you canīt use margin:auto.

Please, check my profile, and you can see that the menu is very diferent, in fact, donīt think many done it that way yet, though it sort of new,
but will try in css forum as well.

RonPK

11:49 pm on Mar 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Nice CSS solution over here: ht*p://devnull.tagsoup.com/fixed/

In case you still need JavaScript:
1. call your menu 'myMenu'
1. use #myMenu {position: fixed;} for non-IE
2. add this below your CSS-code:

<!--[if IE gte 5 ]>
<style type="text/css">
#myMenu {position: absolute; }
</style>
<![endif]-->

3. add this below the <ul> with the ID myMenu:
<!--[if IE gte 5 ]>
<script language="JScript">
if (document.recalc && document.body.attachEvent) {
myMenu.style.setExpression("top", "document.body.scrollTop + 150");
document.body.onscroll=function(){document.recalc(true)};
}
</script>
<![endif]-->

I have used something like this before, and it works fine, more or less.

Purple Martin

11:53 pm on Mar 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Aaaah... You want it to stay on the screen when the user scrolls down. I understand now.

Yes JavaScript can do this. But it's always unplesantly flickery. Personally I don't like menus that do this. Nevertheless, there are many scripts available on the internet and it has been discussed many times on this site too.

Another way would be to use frames, but frames are bad so I wouldn't do that either.

ADDED AT EDIT:

There are some other (non-JavaScript) hacks to get around IE's lack of position:fixed; support.
[devnull.tagsoup.com...]

helenp

9:12 am on Mar 8, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Thanks both, I tried that link, but I canīt use it, though it must be used with quirks mode.....
so I need an script Iīm afraid.

RonPK: I tried your script but it donīt work at all for me, do you have some url to sticky me, were you are using it?