미디어위키:Gadget-scrollUpButton.js

위키백과, 우리 모두의 백과사전.

참고: 설정을 저장한 후에 바뀐 점을 확인하기 위해서는 브라우저의 캐시를 새로 고쳐야 합니다. 구글 크롬, 파이어폭스, 마이크로소프트 엣지, 사파리: ⇧ Shift 키를 누른 채 "새로 고침" 버튼을 클릭하십시오. 더 자세한 정보를 보려면 위키백과:캐시 무시하기 항목을 참고하십시오.

/* scrollUpButton
* Add a button to scroll up to the top of the current page.
* @rev 4 (2021-05-08)
* @author Kwj2772
* @contributor Perhelion
* No internationalisation required
* [kowiki] Fixed an issue with help-panel-button ([[ko:User:ykhwong]])
* <nowiki>
*/
/* global $:false */
$(function () {
'use strict';

var $icon = '//upload.wikimedia.org/wikipedia/commons/2/2e/Up_%2889591%29_-_The_Noun_Project.svg';
var helpPanelButtonFound = false;

if (!document.implementation.hasFeature('http://www.w3.org/TR/SVG11/feature#Image', '1.1'))
	$icon = '//upload.wikimedia.org/wikipedia/commons/thumb/2/2e/Up_%2889591%29_-_The_Noun_Project.svg/32px-Up_%2889591%29_-_The_Noun_Project.svg.png';

$icon = $('<img>', {
	src: $icon,
	id: 'scrollUpButton',
	class: 'noprint'
}).css({
		position: 'fixed',
		bottom: '50px',
		right: '9px',
		opacity: 0.7,
		width: '32px',
		cursor: 'pointer',
		filter: 'invert(66%) sepia(21%) saturate(761%) hue-rotate(172deg) brightness(99%) contrast(77%)',
		display: 'none'
	}).on('click', function () {
		// Move to the top of the page
		$('html, body').animate({ scrollTop: 0 }, 660);
	}).on('mouseenter mouseleave', function (e) {
		this.style.opacity = e.type === 'mouseenter' ? 1 : 0.7;
	}).appendTo('body');

$(window).on('scroll', function () {
	if (!helpPanelButtonFound && $("#mw-ge-help-panel-cta-button").length > 0) {
		$("img#scrollUpButton").css({
			bottom: '75px'
		});
		helpPanelButtonFound = true;
	}

	// Fade out if you reach the top of the page
	if ($(this).scrollTop() > 60) $icon.fadeIn('30');
	else $icon.fadeOut('30');
});

}());