The editors' meeting has been canceled for technical reasons.

MediaWiki:Common.js:修订间差异

来自NeuroWiki
跳转到导航 跳转到搜索
无编辑摘要
标签已被回退
无编辑摘要
标签已被回退
第1行: 第1行:
/* 这里的任何JavaScript将为所有用户在每次页面加载时加载。 */
// 检查当前页面是否为首页
// 检查当前页面是否为首页
if (mw.config.get('wgPageName') === '首页') {
if (mw.config.get('wgPageName') === '首页') {
// 在指定页面上运行的JavaScript代码
    // 在指定页面上运行的JavaScript代码
document.addEventListener('DOMContentLoaded', function() {
const rotatingDiv = document.getElementById('rotatingDiv');
const div = document.querySelector('.rotating-div');
if (!div) return;  // 确保元素存在
div.addEventListener('mousemove', (event) => {
let currentX = 0;
const rect = div.getBoundingClientRect();
let currentY = 0;
const x = event.clientX - rect.left - rect.width / 2;
const y = event.clientY - rect.top - rect.height / 2;
const maxAngle = 8;
const xAngle = (maxAngle * x) / (rect.width / 2);
const yAngle = -(maxAngle * y) / (rect.height / 2);
const distance = Math.sqrt(x*x + y*y);
const maxDistance = Math.sqrt((rect.width / 2) ** 2 + (rect.height / 2) ** 2);
const colorIntensity = Math.min(1, distance / maxDistance);
const colorValue = 153 + (102 * colorIntensity);
div.style.transform = `rotateX(${yAngle}deg) rotateY(${xAngle}deg)`;
rotatingDiv.addEventListener('mousemove', (event) => {
div.style.backgroundColor = `rgb(${colorValue}, ${colorValue}, ${colorValue})`;
const rect = rotatingDiv.getBoundingClientRect();
});
const x = event.clientX - rect.left - rect.width / 2;
const y = event.clientY - rect.top - rect.height / 2;
div.addEventListener('mouseleave', () => {
// 计算目标角度并限制在±8度
div.style.transform = 'rotateX(0deg) rotateY(0deg)';
const targetX = Math.max(-8, Math.min(8, -y / 30));
div.style.backgroundColor = '#999';
const targetY = Math.max(-8, Math.min(8, x / 30));
});
// 使用缓动算法逐步接近目标角度
currentX += (targetX - currentX) * 0.05; // 速度减慢
currentY += (targetY - currentY) * 0.05; // 速度减慢
// 计算颜色变化
const distance = Math.sqrt(x * x + y * y);
const maxDistance = Math.sqrt((rect.width / 2) ** 2 + (rect.height / 2) ** 2);
const colorRatio = Math.min(1, distance / maxDistance);
const r = Math.floor(52 + (153 - 52) * colorRatio);
const g = Math.floor(152 + (153 - 152) * colorRatio);
const b = Math.floor(219 + (153 - 219) * colorRatio);
// 应用3D旋转和背景颜色变化
rotatingDiv.style.transform = `rotateX(${currentX}deg) rotateY(${currentY}deg)`;
rotatingDiv.style.backgroundColor = `rgb(${r}, ${g}, ${b})`;
// 让文本颜色也逐渐变为灰色
rotatingDiv.style.color = `rgb(${255 - (255 - 153) * colorRatio}, ${255 - (255 - 153) * colorRatio}, ${255 - (255 - 153) * colorRatio})`;
});
rotatingDiv.addEventListener('mouseleave', () => {
// 鼠标离开时恢复初始状态
currentX = 0;
currentY = 0;
rotatingDiv.style.transform = `rotateX(0deg) rotateY(0deg)`;
rotatingDiv.style.backgroundColor = `#3498db`;
rotatingDiv.style.color = `white`;
});
});
}
}

2024年10月28日 (一) 22:04的版本

// 检查当前页面是否为首页
if (mw.config.get('wgPageName') === '首页') {
    // 在指定页面上运行的JavaScript代码
	const rotatingDiv = document.getElementById('rotatingDiv');
	
	let currentX = 0;
	let currentY = 0;
	
	rotatingDiv.addEventListener('mousemove', (event) => {
		const rect = rotatingDiv.getBoundingClientRect();
		const x = event.clientX - rect.left - rect.width / 2;
		const y = event.clientY - rect.top - rect.height / 2;
	
		// 计算目标角度并限制在±8度
		const targetX = Math.max(-8, Math.min(8, -y / 30));
		const targetY = Math.max(-8, Math.min(8, x / 30));
	
		// 使用缓动算法逐步接近目标角度
		currentX += (targetX - currentX) * 0.05; // 速度减慢
		currentY += (targetY - currentY) * 0.05; // 速度减慢
	
		// 计算颜色变化
		const distance = Math.sqrt(x * x + y * y);
		const maxDistance = Math.sqrt((rect.width / 2) ** 2 + (rect.height / 2) ** 2);
		const colorRatio = Math.min(1, distance / maxDistance);
		const r = Math.floor(52 + (153 - 52) * colorRatio);
		const g = Math.floor(152 + (153 - 152) * colorRatio);
		const b = Math.floor(219 + (153 - 219) * colorRatio);
	
		// 应用3D旋转和背景颜色变化
		rotatingDiv.style.transform = `rotateX(${currentX}deg) rotateY(${currentY}deg)`;
		rotatingDiv.style.backgroundColor = `rgb(${r}, ${g}, ${b})`;
	
		// 让文本颜色也逐渐变为灰色
		rotatingDiv.style.color = `rgb(${255 - (255 - 153) * colorRatio}, ${255 - (255 - 153) * colorRatio}, ${255 - (255 - 153) * colorRatio})`;
	});
	
	rotatingDiv.addEventListener('mouseleave', () => {
		// 鼠标离开时恢复初始状态
		currentX = 0;
		currentY = 0;
		rotatingDiv.style.transform = `rotateX(0deg) rotateY(0deg)`;
		rotatingDiv.style.backgroundColor = `#3498db`;
		rotatingDiv.style.color = `white`;
	});
}