The editors' meeting has been canceled for technical reasons.

MediaWiki:Common.js:修订间差异

来自NeuroWiki
跳转到导航 跳转到搜索
创建页面,内容为“→‎这里的任何JavaScript将为所有用户在每次页面加载时加载。:​ // 检查当前页面是否为首页 if (mw.config.get('wgPageName') === '首页') { // 在指定页面上运行的JavaScript代码 const rotatingDiv = document.getElementById('rotatingDiv'); rotatingDiv.addEventListener('mousemove', (event) => { const rect = rotatingDiv.getBoundingClientRect(); const x = event.clientX - rect.left - rect.width / 2; const y = event…”
 
无编辑摘要
标签已被回退
第3行: 第3行:
if (mw.config.get('wgPageName') === '首页') {
if (mw.config.get('wgPageName') === '首页') {
     // 在指定页面上运行的JavaScript代码
     // 在指定页面上运行的JavaScript代码
    const rotatingDiv = document.getElementById('rotatingDiv');
const rotatingDiv = document.getElementById('rotatingDiv');
 
let currentX = 0;
let currentY = 0;
let currentZ = 0;
rotatingDiv.addEventListener('mousemove', (event) => {
rotatingDiv.addEventListener('mousemove', (event) => {
const rect = rotatingDiv.getBoundingClientRect();
  const rect = rotatingDiv.getBoundingClientRect();
const x = event.clientX - rect.left - rect.width / 2;
  const x = event.clientX - rect.left - rect.width / 2;
const y = event.clientY - rect.top - rect.height / 2;
  const y = event.clientY - rect.top - rect.height / 2;
  // 计算目标角度并限制在±10度
  const targetX = Math.max(-10, Math.min(10, -y / 20));
  const targetY = Math.max(-10, Math.min(10, x / 20));
  const targetZ = Math.max(-10, Math.min(10, (x - y) / 40)); // 简单添加Z轴效果
// 根据鼠标位置计算旋转角度
  // 使用缓动算法逐步接近目标角度
const rotateX = -y / 10; // 负号用于反转方向
  currentX += (targetX - currentX) * 0.1;
const rotateY = x / 10;
  currentY += (targetY - currentY) * 0.1;
  currentZ += (targetZ - currentZ) * 0.1;
// 应用3D旋转
  // 应用3D旋转
rotatingDiv.style.transform = `rotateX(${rotateX}deg) rotateY(${rotateY}deg)`;
  rotatingDiv.style.transform = `rotateX(${currentX}deg) rotateY(${currentY}deg) rotateZ(${currentZ}deg)`;
});
});
rotatingDiv.addEventListener('mouseleave', () => {
rotatingDiv.addEventListener('mouseleave', () => {
// 鼠标离开时恢复初始状态
  // 鼠标离开时恢复初始状态
rotatingDiv.style.transform = `rotateX(0deg) rotateY(0deg)`;
  currentX = 0;
  currentY = 0;
  currentZ = 0;
  rotatingDiv.style.transform = `rotateX(0deg) rotateY(0deg) rotateZ(0deg)`;
});
});
    // 你可以在这里添加任何特定于页面的JS代码
}
}

2024年10月28日 (一) 21:44的版本

/* 这里的任何JavaScript将为所有用户在每次页面加载时加载。 */
// 检查当前页面是否为首页
if (mw.config.get('wgPageName') === '首页') {
    // 在指定页面上运行的JavaScript代码
	const rotatingDiv = document.getElementById('rotatingDiv');
	
	let currentX = 0;
	let currentY = 0;
	let currentZ = 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;
	
	  // 计算目标角度并限制在±10度
	  const targetX = Math.max(-10, Math.min(10, -y / 20));
	  const targetY = Math.max(-10, Math.min(10, x / 20));
	  const targetZ = Math.max(-10, Math.min(10, (x - y) / 40)); // 简单添加Z轴效果
	
	  // 使用缓动算法逐步接近目标角度
	  currentX += (targetX - currentX) * 0.1;
	  currentY += (targetY - currentY) * 0.1;
	  currentZ += (targetZ - currentZ) * 0.1;
	
	  // 应用3D旋转
	  rotatingDiv.style.transform = `rotateX(${currentX}deg) rotateY(${currentY}deg) rotateZ(${currentZ}deg)`;
	});
	
	rotatingDiv.addEventListener('mouseleave', () => {
	  // 鼠标离开时恢复初始状态
	  currentX = 0;
	  currentY = 0;
	  currentZ = 0;
	  rotatingDiv.style.transform = `rotateX(0deg) rotateY(0deg) rotateZ(0deg)`;
	});
}