javascript文本文字跟随鼠标显示层叠拆分动画效果

所属分类: 网页特效-动画效果    2024-03-25 03:05:37

javascript文本文字跟随鼠标显示层叠拆分动画效果 ie兼容6
反馈问题  查看演示  登录后下载 温馨提示
登录会员即可享受免费下载
 我要建站

javascript文本文字跟随鼠标显示层叠拆分动画效果(共3个文件)

    • index.html

使用方法

function getTwoDecimal(num) {
  // The +0.5 smoothens the transition change
  return parseFloat(num.toFixed(2) + 0.5);
}

const mouse = {
  decimal(coord) {
    return getTwoDecimal(coord / 1000);
  },
  x(e) {
    return Math.abs(e.clientX - window.innerWidth / 2);
  },
  y(e) {
    return Math.abs(e.clientY - window.innerHeight / 2);
  } };


const changeTextAlphaVal = (txt, e) => {
  const root = document.querySelector(":root");
  const cssVar = "--alpha";
  const currentAlpha = getComputedStyle(root).
  getPropertyValue(cssVar).
  trim();

  const max = parseFloat(currentAlpha);
  const dx = mouse.decimal(mouse.x(e));
  const dy = mouse.decimal(mouse.y(e));

  let alphaVal;
  if (dx <= 0) {
    alphaVal = dy >= max ? dy : getTwoDecimal(max - dy);
  } else {
    alphaVal = dx >= max ? dx : getTwoDecimal(max - dx);
  }

  txt.style.setProperty(cssVar, alphaVal);
};

function createShadow(e, currTarget) {
  // Walk effect based on Wes Bos' Mouse Move Shadow Exercise
  // https://tinyurl.com/touabxe
  const walk = Math.round(Math.max(window.innerWidth, window.innerHeight) / 6); // Or use 150?
  const coordWalk = (coord, side) => Math.round(coord / side * walk - walk / 2);
  const xWalk = coordWalk(e.clientX, currTarget.offsetWidth);
  const yWalk = coordWalk(e.clientY, currTarget.offsetHeight);

  const pink = [255, 0, 139];
  const blue = [0, 86, 255];
  const yellow = [255, 240, 0];
  const typoAlpha = 0.6;

  const typo = currTarget.querySelector(".typo");
  changeTextAlphaVal(typo, e); // Comment this if you don't want the text alpha opacity to change on interaction

  typo.style.textShadow = `
	  ${xWalk}px ${yWalk}px 0 rgba(${pink}, ${typoAlpha}),
	  ${xWalk * -1}px ${yWalk * 2}px 0 rgba(${blue}, ${typoAlpha}),
	  ${xWalk * -2}px ${yWalk * -1}px 0 rgba(${yellow}, ${typoAlpha})
	`;
}

function onMouseMove(e) {
  createShadow(e, e.currentTarget);
}
function onTouchMove(e) {
  createShadow(e.changedTouches[0], e.currentTarget);
}

const heading = document.querySelector(".heading");
heading.addEventListener("mousemove", onMouseMove);
heading.addEventListener("touchmove", onTouchMove);

站长提示:
1. 平台上所有素材资源,需注册登录会员方能正常下载。
2. 会员用户积极反馈网站、素材资源BUG或错误问题,每次奖励20K币
3. PHP源码类素材,如需协助安装调试,或你有二次开发需求,可联系苦力吧客服。
4. 付费素材资源,需充值后方能下载,如有任何疑问可直接联系苦力吧客服
相关资源 / 动画效果

jquery使用SVG生成的不规则动画图形背景特效代码

一个背景动画特效插件,使用SVG生成动画图形斑点,作为网页背景随机运动。
  动画效果
 105  

JavaScript实现的像素小方块图片背景动画特效代码

JavaScript代码创建的一个动态的像素背景动画。该代码生成一个随着时间推移而移动和衰减的正方形网格。可通过鼠标点击、生成新的方块或重置现有方块进行交互。
  动画效果
 75  

html5网页背景动画插件_酷炫背景动画特效

带多种不同的动画背景特效,可在线选择触发显示!
  动画效果
 187  

js鼠标悬停网格卡片触发堆叠动画特效代码

一款悬停卡片触发的堆叠动画特效,它使用了CSS平移和旋转变换使卡片等距堆叠效果,鼠标悬停于卡片上即可触发效果。
  动画效果
 83  

评论数(0) 回复有机会获得K币 用户协议

^_^ 还没有人评论,快来抢个沙发!
😀
  • 😀
  • 😊
  • 😂
  • 😍
  • 😑
  • 😷
  • 😵
  • 😛
  • 😣
  • 😱
  • 😋
  • 😎
  • 😵
  • 😕
  • 😶
  • 😚
  • 😜
  • 😭
发表评论