The editors' meeting has been canceled for technical reasons.

MediaWiki:Common.js:修订间差异

来自NeuroWiki
跳转到导航 跳转到搜索
无编辑摘要
标签手工回退
无编辑摘要
 
(未显示同一用户的8个中间版本)
第1行: 第1行:
/* 这里的任何JavaScript将为所有用户在每次页面加载时加载。 */
/* 这里的任何JavaScript将为所有用户在每次页面加载时加载。 */
// 检查当前页面是否为首页
// 检查当前页面的标题或 URL 是否符合条件
if (mw.config.get('wgPageName') === '首页') {
$(function () {
    // 在指定页面上运行的JavaScript代码
  // 如果页面上没有 .bouncing-container,则无需执行
    const rotatingDiv = document.getElementById('rotatingDiv');
  if (!$('.bouncing-container').length) return;


rotatingDiv.addEventListener('mousemove', (event) => {
  $('.bouncing-container').each(function () {
const rect = rotatingDiv.getBoundingClientRect();
    const $container = $(this);
const x = event.clientX - rect.left - rect.width / 2;
    const $div = $container.find('.bouncing-div');
const y = event.clientY - rect.top - rect.height / 2;
 
    // 检查是否启用变色功能
// 根据鼠标位置计算旋转角度
    const changeColor = $container.data('changecolor') === 'yes';
const rotateX = -y / 10; // 负号用于反转方向
 
const rotateY = x / 10;
    // 读取倍速参数
    const speedMultiplier = parseFloat($container.data('speed')) || 1;
// 应用3D旋转
 
rotatingDiv.style.transform = `rotateX(${rotateX}deg) rotateY(${rotateY}deg)`;
    // 初始化位置和速度
});
    let x = Math.random() * ($container.width() - $div.width());
    let y = Math.random() * ($container.height() - $div.height());
rotatingDiv.addEventListener('mouseleave', () => {
    let dx = (Math.random() < 0.5 ? -1 : 1) * (2 + Math.random() * 2) * speedMultiplier; // x 速度乘以倍速
// 鼠标离开时恢复初始状态
    let dy = (Math.random() < 0.5 ? -1 : 1) * (2 + Math.random() * 2) * speedMultiplier; // y 速度乘以倍速
rotatingDiv.style.transform = `rotateX(0deg) rotateY(0deg)`;
 
});
    // 设置初始位置
     // 你可以在这里添加任何特定于页面的JS代码
    $div.css({ left: x, top: y });
}
 
    // 随机颜色生成函数
    function getRandomColor() {
      const letters = '0123456789ABCDEF';
      let color = '#';
      for (let i = 0; i < 6; i++) {
        color += letters[Math.floor(Math.random() * 16)];
      }
      return color;
    }
 
    // 偏移角度函数
    function applyRandomAngleOffset() {
      // 20% 的概率应用随机偏移
      if (Math.random() < 0.2) {
        const angleOffset = (Math.random() * 5 - 2.5) * (Math.PI / 180); // -2.5° 到 2.5° 的弧度
        const speed = Math.sqrt(dx * dx + dy * dy); // 当前速度大小
        const angle = Math.atan2(dy, dx); // 当前角度
 
        // 应用角度偏移
        const newAngle = angle + angleOffset;
        dx = speed * Math.cos(newAngle);
        dy = speed * Math.sin(newAngle);
      }
    }
 
    // 移动和碰撞检测函数
    function move() {
      x += dx;
      y += dy;
 
      // 碰撞检测
      let collision = false;
 
      if (x <= 0 || x + $div.width() >= $container.width()) {
        dx = -dx; // 反向 x
        collision = true;
        applyRandomAngleOffset(); // 应用随机角度偏移
      }
      if (y <= 0 || y + $div.height() >= $container.height()) {
        dy = -dy; // 反向 y
        collision = true;
        applyRandomAngleOffset(); // 应用随机角度偏移
      }
 
      // 如果发生碰撞并且启用变色
      if (collision && changeColor) {
        $div.css('background-color', getRandomColor());
      }
 
      // 更新位置
      $div.css({ left: x, top: y });
 
      // 使用 requestAnimationFrame 来平滑动画
      requestAnimationFrame(move);
    }
 
     // 开始动画
    move();
  });
});

2025年1月24日 (五) 01:54的最新版本

/* 这里的任何JavaScript将为所有用户在每次页面加载时加载。 */
// 检查当前页面的标题或 URL 是否符合条件
$(function () {
  // 如果页面上没有 .bouncing-container,则无需执行
  if (!$('.bouncing-container').length) return;

  $('.bouncing-container').each(function () {
    const $container = $(this);
    const $div = $container.find('.bouncing-div');

    // 检查是否启用变色功能
    const changeColor = $container.data('changecolor') === 'yes';

    // 读取倍速参数
    const speedMultiplier = parseFloat($container.data('speed')) || 1;

    // 初始化位置和速度
    let x = Math.random() * ($container.width() - $div.width());
    let y = Math.random() * ($container.height() - $div.height());
    let dx = (Math.random() < 0.5 ? -1 : 1) * (2 + Math.random() * 2) * speedMultiplier; // x 速度乘以倍速
    let dy = (Math.random() < 0.5 ? -1 : 1) * (2 + Math.random() * 2) * speedMultiplier; // y 速度乘以倍速

    // 设置初始位置
    $div.css({ left: x, top: y });

    // 随机颜色生成函数
    function getRandomColor() {
      const letters = '0123456789ABCDEF';
      let color = '#';
      for (let i = 0; i < 6; i++) {
        color += letters[Math.floor(Math.random() * 16)];
      }
      return color;
    }

    // 偏移角度函数
    function applyRandomAngleOffset() {
      // 20% 的概率应用随机偏移
      if (Math.random() < 0.2) {
        const angleOffset = (Math.random() * 5 - 2.5) * (Math.PI / 180); // -2.5° 到 2.5° 的弧度
        const speed = Math.sqrt(dx * dx + dy * dy); // 当前速度大小
        const angle = Math.atan2(dy, dx); // 当前角度

        // 应用角度偏移
        const newAngle = angle + angleOffset;
        dx = speed * Math.cos(newAngle);
        dy = speed * Math.sin(newAngle);
      }
    }

    // 移动和碰撞检测函数
    function move() {
      x += dx;
      y += dy;

      // 碰撞检测
      let collision = false;

      if (x <= 0 || x + $div.width() >= $container.width()) {
        dx = -dx; // 反向 x
        collision = true;
        applyRandomAngleOffset(); // 应用随机角度偏移
      }
      if (y <= 0 || y + $div.height() >= $container.height()) {
        dy = -dy; // 反向 y
        collision = true;
        applyRandomAngleOffset(); // 应用随机角度偏移
      }

      // 如果发生碰撞并且启用变色
      if (collision && changeColor) {
        $div.css('background-color', getRandomColor());
      }

      // 更新位置
      $div.css({ left: x, top: y });

      // 使用 requestAnimationFrame 来平滑动画
      requestAnimationFrame(move);
    }

    // 开始动画
    move();
  });
});