This is doing my head in. In my code below, I set the style of a div
so that its position is absolute and top = 50. When I view it in my
browser it is positioned correctly. But, if I use pixelTop (or top)
to change the position by adding one, my first mouse click is moving
the div to top = 1, instead of top = 51!
I've done some investigating using alert and it seems that height, top
and pixelTop all have an initial value of zero until I set them with
JS??!
What am I doing wrong?
Thanks
Martin
<html>
<head>
<style>
..myHead
{
width:100px;
height:50px;
background-color:blue;
position:absolu te;
}
..myBody
{
width:100px;
height:50px;
background-color:red;
position:absolu te;
top:50;
}
</style>
</head>
<body>
<script language="javas cript">
function myMove()
{
myBody.style.pi xelTop = myBody.style.pi xelTop + 1;
}
</script>
<div id="myHead" class="myHead" />
<span id="myBody" class="myBody" onmousedown="my Move()"/>
</body>
</html>
so that its position is absolute and top = 50. When I view it in my
browser it is positioned correctly. But, if I use pixelTop (or top)
to change the position by adding one, my first mouse click is moving
the div to top = 1, instead of top = 51!
I've done some investigating using alert and it seems that height, top
and pixelTop all have an initial value of zero until I set them with
JS??!
What am I doing wrong?
Thanks
Martin
<html>
<head>
<style>
..myHead
{
width:100px;
height:50px;
background-color:blue;
position:absolu te;
}
..myBody
{
width:100px;
height:50px;
background-color:red;
position:absolu te;
top:50;
}
</style>
</head>
<body>
<script language="javas cript">
function myMove()
{
myBody.style.pi xelTop = myBody.style.pi xelTop + 1;
}
</script>
<div id="myHead" class="myHead" />
<span id="myBody" class="myBody" onmousedown="my Move()"/>
</body>
</html>
Comment