PDA

View Full Version : location of div



emanuelle
04-11-2007, 10:50 AM
I would like to position my div according to where I am located on my page

Twey
04-11-2007, 11:25 AM
And where are you located on your page?

emanuelle
04-11-2007, 11:45 AM
its page with many link calling for "floating divs".
so I want my div to appear more or elss where the link is

mburt
04-11-2007, 03:46 PM
Wrote this script yesterday:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Hover</title>
<style type="text/css">
.dialog {
position:absolute;
padding:3px;
border:1px solid gray;
font:10pt arial;
display:none;
}
</style>
<script type="text/javascript">
function show(cur,element) {
var el = document.getElementById(element);
if (el.style.display == "block") {
el.style.display = "none";
}
else {
el.style.left = cur.offsetLeft+"px";
el.style.top = cur.offsetTop+cur.offsetHeight+"px";
el.style.display = "block";
}
return false;
}
</script>
</head>
<body>
<a href="#" onclick="return show(this,'dlg1');">Test</a>
<div id="dlg1" class="dialog">
Text to show.
</div>
</body>
</html>
Whereas, the "text to show" is where your div content is.

emanuelle
04-11-2007, 05:34 PM
thank you very much

is there a way I can define that the div will be on top of the link(not bottom)

mburt
04-11-2007, 05:44 PM
Replace:

el.style.top = cur.offsetTop+cur.offsetHeight+"px"
With:

el.style.top = cur.offsetTop-cur.offsetHeight-el.offsetHeight+"px"