미디어위키:Common.js: 두 판 사이의 차이
둘러보기로 이동
검색으로 이동
Resultofunion (토론 | 기여) 편집 요약 없음 |
Resultofunion (토론 | 기여) 편집 요약 없음 |
||
| 2번째 줄: | 2번째 줄: | ||
/* TOP 버튼 */ | /* TOP 버튼 */ | ||
var topButton = document.createElement('div'); | |||
topButton.id="top-button"; | topButton.id="top-button"; | ||
document.body.appendChild(topButton); | document.body.appendChild(topButton); | ||
2022년 1월 13일 (목) 14:40 판
/* 이 자바스크립트 설정은 모든 문서, 모든 사용자에게 적용됩니다. */
/* TOP 버튼 */
var 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);
}
});