JAVASCRIPT 따라 다니는 구석의 DIV

<html>
<head>
<style>
#image {
WIDTH: 160px; top: 350px; POSITION: absolute
}
</style>

<script language="javascript">

// 고정 위치를 결정해 줍니다.
var topOffset = 0
var HANDLER;

function smoothMove() {
// 1보다 작은 수를 곱하면 부드럽게 이동합니다.(0.1정도)
var Dif = parseInt(document.body.scrollTop+topOffset-document.all.image.offsetTop * 1)
// Work-around wierd Netscape NaN bug when Dif is 0
// Netscape 일때 처리
// if (isNaN(Dif)) Dif=0
document.all.image.style.pixelTop+=Dif
}

function doLoad() {
HANDLER = window.setInterval("smoothMove()",20)
document.all.image.style.left=document.body.clientWidth-parseInt(document.all.image.style.width);
// 하단인경우 주석을 해지
topOffset = document.body.clientHeight-parseInt(document.all.image.style.height);
}

</script>
</head>

<body onLoad="doLoad();">
<div id="image" style="width:40px; height:20px; position:absolute; left:0; top:0; z-index:1; background-color:#C0C0C0">
<a href="#">위로</a>
</div>
<script>
for(i=0;i<=300;i++)
{
document.write(i+"<br>");
}
</script>
</body>
</html>

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다