Avatar billede ripley Nybegynder
01. december 2003 - 14:41 Der er 5 kommentarer og
1 løsning

Positionering på skærm i forhold til skærmopløsning /vinduets str

Jeg har følgende kode, der giver en menu, der glider ind fra toppen.
Jeg skal have det til at virke, så det placerer sig samme sted, uanset skærmopløsning og uanset om vinduet er gjort større eller mindre.
Er det helt umuligt???

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Slide-down-menu</title>
<meta name="Generator" content="Stone's WebWriter 4">
<meta name="keywords" content="roenving,http://www.eksperten.dk/spm/434485">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Original:  David Sosnowski (support@codelifter.com) -->
<!-- Web Site:  http://www.codelifter.com -->
<!-- Modified 20031201 to support Slide-down instead of Glide-in-->
<!--
Put the <style> script in the <head> of your page.
Set up the border, background-color, padding, and
font elements as needed. Leave the position as is.
Width and height can be set as auto, or you can
specify these in pixels.
//-->

<style>

#menuShow{
border: 1px solid #666666;
background-color: #111111;
padding: 13px;
font-size: 13px;
font-family: Verdana, Arial;
position: absolute;
width: auto;
height: auto;
}

#menuSelect{
border: 1px solid #666666;
background-color: #111111;
padding: 13px;
font-size: 13px;
font-family: Verdana, Arial;
position: absolute;
width: auto;
height: auto;
}

</style>
</head>

<body>

<!--
Place the two <div>'s below in the <body> of your code.
(Normally, this will be immediately after the <body>
tag.) The menuShow div will contain your links; change
the text, links, and targets as needed.
//-->

<div id="menuSelect">
<a href="#" onclick="moveOnMenu();moveOffSelector()">
<img src="icon.gif" width="28" height="28" border="0"></a>
</div>
<div id="menuShow">
<a href="#" onclick="moveOffMenu();moveOnSelector()">
<img src="icon.gif" width="28" height="28" border="0"></a>
<br>
<br>
<a href="http://www.codelifter.com">Menu Item A</a><br>
<a href="http://www.codelifter.com">Menu Item B</a><br>
<a href="http://www.codelifter.com">Menu Item C</a><br>
<br>
<a href="http://www.codelifter.com">Menu Item D</a><br>
<a href="http://www.codelifter.com">Menu Item E</a><br>
<br>
<a href="http://www.codelifter.com">Menu Item F</a><br>
<a href="http://www.codelifter.com">Menu Item G</a><br>
<a href="http://www.codelifter.com">Menu Item H</a><br>
</div>

<!--
Put the following script immediately *after* the
<div>'s (above) in your page. Set the variables as
indicated in the script.
//-->

<script language="JavaScript">
<!-- Original:  David Sosnowski (support@codelifter.com) -->
<!-- Web Site:  http://www.codelifter.com -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
// (C) 2001 www.CodeLifter.com
// http://www.codelifter.com
// Free for all users, but leave in this header.

// Set Show to "yes" to show the menu on start-up.
// Set Show to "no" to show the selector on start-up.

Show ="yes";

// Set OffX in pixels to a negative number
// somewhat larger than the height of the menu.

var OffY = -300;

// Set the PosX and PosY variables
// to the location on the screen where the
// menu should position (in pixels) when stopped.

var PosX =  250;
var PosY =  100;

// Usually, use the settings shown; but you can
// change the speed and the increment of motion
// across the screen, below.

var speed        = 1;
var increment    = 1;
var incrementNS4 = 5; // for slower NS4 browsers

// do not edit below this line
// ===========================

var is_NS = navigator.appName=="Netscape";
var is_Ver = parseInt(navigator.appVersion);
var is_NS4 = is_NS&&is_Ver>=4&&is_Ver<5;
var is_NS5up = is_NS&&is_Ver>=5;

var MenuY = OffY;
var SelY = PosY;
var sPosY = PosY;
var sOffY = OffY;

if (Show == "yes") {
sPosY = OffY;
sOffY = PosY;
MenuY = sOffY;
SelY = sPosY;
}

if (is_NS4) {
increment = incrementNS4;
Lq = "document.layers.";
Sq = "";
eval(Lq+'menuSelect'+Sq+'.top=sPosY');
eval(Lq+'menuShow'+Sq+'.top=sOffY');
eval(Lq+'menuSelect'+Sq+'.left=PosX');
eval(Lq+'menuShow'+Sq+'.left=PosX');
} else {
Lq = "document.all.";
Sq = ".style";
document.getElementById('menuSelect').style.top = sPosY+"px";
document.getElementById('menuShow').style.top = sOffY+"px";
document.getElementById('menuSelect').style.left = PosX+"px";
document.getElementById('menuShow').style.left = PosX+"px";


function moveOnMenu() {
if (MenuY < PosY) {
MenuY = MenuY + increment;
if (is_NS5up) {
document.getElementById('menuShow').style.top = MenuY+"px";
} else {
eval(Lq+'menuShow'+Sq+'.top=MenuY');
}
setTimeout('moveOnMenu()',speed);
  }
}

function moveOffMenu() {
if (MenuY > OffY) {
MenuY = MenuY - increment;
if (is_NS5up) {
document.getElementById('menuShow').style.top = MenuY+"px";
} else {
eval(Lq+'menuShow'+Sq+'.top=MenuY');
}
setTimeout('moveOffMenu()',speed);
  }
}

function moveOffSelector() {
if (SelY > OffY) {
SelY = SelY - increment;
if (is_NS5up) {
document.getElementById('menuSelect').style.top = SelY+"px";
} else {
eval(Lq+'menuSelect'+Sq+'.top=SelY');
}
setTimeout('moveOffSelector()',speed);
  }
}

function moveOnSelector() {
if (SelY < PosY) {
SelY = SelY + increment;
if (is_NS5up) {
document.getElementById('menuSelect').style.top = SelY+"px";
} else {
eval(Lq+'menuSelect'+Sq+'.top=SelY');
}
setTimeout('moveOnSelector()',speed);
  }
}
//  End -->
</script>
</body>
</html>
Avatar billede roenving Novice
01. december 2003 - 14:44 #1
Har du et element, som fastlægger hvor placeringen skal være ?-)

-- for så kan vi finde det elements placering onload og indstille placeringen ...
Avatar billede ripley Nybegynder
01. december 2003 - 15:18 #2
Hm - den er i en table?
Avatar billede roenving Novice
01. december 2003 - 15:35 #3
Så giv tablecellen en id, og så må vi bruge getPos() til at finde placeringen:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Slide-down-menu</title>
<meta name="Generator" content="Stone's WebWriter 4">
<meta name="keywords" content="roenving,http://www.eksperten.dk/spm/434485">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Original:  David Sosnowski (support@codelifter.com) -->
<!-- Web Site:  http://www.codelifter.com -->
<!-- Modified 20031201 to support Slide-down instead of Glide-in-->
<!--
Put the <style> script in the <head> of your page.
Set up the border, background-color, padding, and
font elements as needed. Leave the position as is.
Width and height can be set as auto, or you can
specify these in pixels.
//-->

<style>

#menuShow{
border: 1px solid #666666;
background-color: #111111;
padding: 13px;
font-size: 13px;
font-family: Verdana, Arial;
position: absolute;
width: auto;
height: auto;
}

#menuSelect{
border: 1px solid #666666;
background-color: #111111;
padding: 13px;
font-size: 13px;
font-family: Verdana, Arial;
position: absolute;
width: auto;
height: auto;
}

</style>
</head>

<body onload="posMenu()" onresize="posMenu()">

<table>
    <tr>
        <td style="width:300px;">&nbsp;</td>
        <td id="menuTd">&nbsp;</td>
        <td style="width:300px;">&nbsp;</td>
    </tr>
</table>

<!--
Place the two <div>'s below in the <body> of your code.
(Normally, this will be immediately after the <body>
tag.) The menuShow div will contain your links; change
the text, links, and targets as needed.
//-->

<div id="menuSelect">
<a href="#" onclick="moveOnMenu();moveOffSelector()">
<img src="icon.gif" width="28" height="28" border="0"></a>
</div>
<div id="menuShow">
<a href="#" onclick="moveOffMenu();moveOnSelector()">
<img src="icon.gif" width="28" height="28" border="0"></a>
<br>
<br>
<a href="http://www.codelifter.com">Menu Item A</a><br>
<a href="http://www.codelifter.com">Menu Item B</a><br>
<a href="http://www.codelifter.com">Menu Item C</a><br>
<br>
<a href="http://www.codelifter.com">Menu Item D</a><br>
<a href="http://www.codelifter.com">Menu Item E</a><br>
<br>
<a href="http://www.codelifter.com">Menu Item F</a><br>
<a href="http://www.codelifter.com">Menu Item G</a><br>
<a href="http://www.codelifter.com">Menu Item H</a><br>
</div>

<!--
Put the following script immediately *after* the
<div>'s (above) in your page. Set the variables as
indicated in the script.
//-->

<script language="JavaScript">
<!-- Original:  David Sosnowski (support@codelifter.com) -->
<!-- Web Site:  http://www.codelifter.com -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
// (C) 2001 www.CodeLifter.com
// http://www.codelifter.com
// Free for all users, but leave in this header.

// Set Show to 'true' to show the menu on start-up.
// Set Show to 'false' to show the selector on start-up.

Show = true;

// Set OffX in pixels to a negative number
// somewhat larger than the height of the menu.

var OffY = -300;

// Set the PosX and PosY variables
// to the location on the screen where the
// menu should position (in pixels) when stopped.

var PosX =  250;
var PosY =  100;

// Usually, use the settings shown; but you can
// change the speed and the increment of motion
// across the screen, below.

var speed        = 1;
var increment    = 1;
var incrementNS4 = 5; // for slower NS4 browsers

// do not edit below this line
// ===========================

var is_NS = navigator.appName=="Netscape";
var is_Ver = parseInt(navigator.appVersion);
var is_NS4 = is_NS&&is_Ver>=4&&is_Ver<5;
var is_NS5up = is_NS&&is_Ver>=5;

var MenuY, SelY, sPosY, sOffY, zx,zy;

function posMenu(){
var elm = document.getElementById('menuTd');

//jumper
    for(zx=zy=0;elm!=null;zx+=elm.offsetLeft,zy+=elm.offsetTop,elm=elm.offsetParent);
   
MenuY = OffY;
SelY = zy+1;
sPosY = zy+1;
sOffY = OffY;

if (Show == "yes") {
sPosY = OffY;
sOffY = zy+1;
MenuY = sOffY;
SelY = sPosY;
}

if (is_NS4) {
increment = incrementNS4;
Lq = "document.layers.";
Sq = "";
eval(Lq+'menuSelect'+Sq+'.top=sPosY');
eval(Lq+'menuShow'+Sq+'.top=sOffY');
eval(Lq+'menuSelect'+Sq+'.left=zx+1');
eval(Lq+'menuShow'+Sq+'.left=zx+1');
} else {
Lq = "document.all.";
Sq = ".style";
document.getElementById('menuSelect').style.top = sPosY+"px";
document.getElementById('menuShow').style.top = sOffY+"px";
document.getElementById('menuSelect').style.left = (zx+1)+"px";
document.getElementById('menuShow').style.left = (zx+1)+"px";

}

function moveOnMenu() {
if (MenuY < zy+1) {
MenuY = MenuY + increment;
if (is_NS5up) {
document.getElementById('menuShow').style.top = MenuY+"px";
} else {
eval(Lq+'menuShow'+Sq+'.top=MenuY');
}
setTimeout('moveOnMenu()',speed);
  }
  Show = !Show;
}

function moveOffMenu() {
if (MenuY > OffY) {
MenuY = MenuY - increment;
if (is_NS5up) {
document.getElementById('menuShow').style.top = MenuY+"px";
} else {
eval(Lq+'menuShow'+Sq+'.top=MenuY');
}
setTimeout('moveOffMenu()',speed);
  }
  Show = !Show;
}

function moveOffSelector() {
if (SelY > OffY) {
SelY = SelY - increment;
if (is_NS5up) {
document.getElementById('menuSelect').style.top = SelY+"px";
} else {
eval(Lq+'menuSelect'+Sq+'.top=SelY');
}
setTimeout('moveOffSelector()',speed);
  }
}

function moveOnSelector() {
if (SelY < zy+1) {
SelY = SelY + increment;
if (is_NS5up) {
document.getElementById('menuSelect').style.top = SelY+"px";
} else {
eval(Lq+'menuSelect'+Sq+'.top=SelY');
}
setTimeout('moveOnSelector()',speed);
  }
}
//  End -->
</script>
</body>
</html>
Avatar billede ripley Nybegynder
03. december 2003 - 10:44 #4
Du er for sej, roenving!
Svar og du får dine points! :o)
Avatar billede roenving Novice
04. december 2003 - 01:07 #5
Velbekomme '-)
Avatar billede roenving Novice
09. december 2003 - 17:00 #6
-- og tak for points ;~}
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Vi tilbyder markedets bedste kurser inden for webudvikling

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester