- 정보공유
[기타] 화면 하단 TOP 버튼
화면이 길어질경우 버튼을 클릭하여 상단으로 올라가게 하고싶을경우.
JAVASCRIPT
function go_top(orix, oriy, desx, desy) {
var Timer;
if (document.body.scrollTop == 0) {
var winHeight = document.documentElement.scrollTop;
} else {
var winHeight = document.body.scrollTop;
}
if (Timer) clearTimeout(Timer);
startx = 0;
starty = winHeight;
if (!orix || orix < 0) orix = 0;
if (!oriy || oriy < 0) oriy = 0;
var speed = 7;
if (!desx) desx = 0 + startx;
if (!desy) desy = 0 + starty;
desx += (orix - startx) / speed;
if (desx < 0) desx = 0;
desy += (oriy - starty) / speed;
if (desy < 0) desy = 0;
var posX = Math.ceil(desx);
var posY = Math.ceil(desy);
window.scrollTo(posX, posY);
if ((Math.floor(Math.abs(startx - orix)) < 1) && (Math.floor(Math.abs(starty - oriy)) < 1)) {
clearTimeout(Timer);
window.scroll(orix, oriy);
} else if (posX != orix || posY != oriy) {
Timer = setTimeout("go_top(" + orix + "," + oriy + "," + desx + "," + desy + ")", 15);
} else {
clearTimeout(Timer);
}
}
HTML
<a style="z-index:9999;display:scroll;position:fixed;bottom:8px;right:10px;" onclick="go_top();" title="top"><img src="./top.png" border=0 style="cursor:pointer" /></a>
IMAGE 파일.