2018. 6. 14. 10:36
아래 소스를 <head></head> 사이에 입력해준다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | <script type="text/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); } } </script> | cs |
탑버튼 링크 아래와 같이 변경해준다.
1 | <a onclick="go_top();"> 텍스트/이미지<img src=""></a> | cs |