미디어위키:Common.js: 두 판 사이의 차이
Resultofunion (토론 | 기여) 편집 요약 없음 |
Resultofunion (토론 | 기여) 편집 요약 없음 |
||
| 1번째 줄: | 1번째 줄: | ||
/* 이 자바스크립트 설정은 모든 문서, 모든 사용자에게 적용됩니다. */ | /* 이 자바스크립트 설정은 모든 문서, 모든 사용자에게 적용됩니다. */ | ||
/* TOP 버튼 */ | |||
const topButton = document.createElement('div'); | |||
topButton.id="top-button"; | |||
document.body.appendChild(topButton); | |||
window.addEventListener('scroll', function(e){ | |||
if(window.scrollY > 300){ | |||
topButton.classList.add('active'); | |||
} else { | |||
topButton.classList.remove('active'); | |||
} | |||
}); | |||
topButton.addEventListener('click', function(e){ | |||
try{ | |||
window.scrollTo({ | |||
top: 0, | |||
left: 0, | |||
behavior: 'smooth' | |||
}); | |||
} catch(e){ | |||
window.scrollTo(0, 0); | |||
} | |||
}); | |||