Add interactive cat-follow-cursor demo (single HTML file) - #2
Draft
lobokiol wants to merge 1 commit into
Draft
Conversation
Single-file HTML demo with a layered SVG cat whose head tilts and pupils track the mouse using atan2-based angle math. Includes smooth CSS transitions, periodic and randomized blink animations, touch support, and a fullscreen-friendly responsive layout. Co-authored-by: lobokiol <lobokiol@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概述
新增一个完全自包含的单文件 HTML 演示
cat-follow.html:一只分层 SVG 小猫,头会轻微跟随鼠标倾斜,眼珠也会盯着光标看,并带有平滑过渡和眨眼动画。实现要点
<g>分组):cat-body身体 + 尾巴 + 前爪(不动)cat-head头部(围绕“脖子”做轻微旋转).sclera眼白 / 虹膜(不动).pupil+.glint瞳孔与高光(在椭圆范围内平移)Math.atan2(dy, dx)算出鼠标相对猫脸中心的角度,再按距离归一化映射成:rotate角度(限制 ±8°)translate(x,y)偏移(椭圆范围 ±9px / ±7px)transition+cubic-bezier缓动,避免抖动。@keyframes blink周期性眨眼 + Web Animations API 随机补眨 + 空格键手动触发。vmin缩放,移动端触摸也能跟随。cat-body/cat-head内的形状替换为<image>,并把眼白/瞳孔的cx,cy调到照片对应位置即可。替换为真实猫咪照片的方法
后续上传真实高清猫咪照片后,按下面步骤即可替换:
<g id="cat-body">内部的形状替换为整张照片:<g id="cat-head">内部的“头部形状”替换为去背景后的头部 PNG(以便整头一起倾斜)。<ellipse class="sclera">与<ellipse class="pupil">的cx / cy到照片中眼睛的实际位置。MAX_HEAD_TILT/MAX_PUPIL_OFFSET_*常量微调跟随幅度。试用
直接在浏览器中打开
cat-follow.html即可,无需任何依赖或构建步骤。