Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
0x0007
用HTML生成一个眼睛随着鼠标移动的小宠物
提交
ca769f7d
用
用HTML生成一个眼睛随着鼠标移动的小宠物
项目概览
0x0007
/
用HTML生成一个眼睛随着鼠标移动的小宠物
与 Fork 源项目一致
Fork自
inscode / Streamlit
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
用
用HTML生成一个眼睛随着鼠标移动的小宠物
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
ca769f7d
编写于
12月 01, 2023
作者:
W
weixin_41863029
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fri Dec 1 00:21:00 CST 2023 inscode
上级
40b67534
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
39 addition
and
11 deletion
+39
-11
main.py
main.py
+39
-11
未找到文件。
main.py
浏览文件 @
ca769f7d
...
...
@@ -32,6 +32,16 @@ html = """
st
.
markdown
(
html
,
unsafe_allow_html
=
True
)
css
=
"""
#pet {
width: 200px;
height: 200px;
position: absolute;
left: 50%;
top: 50%;
margin-left: -100px;
margin-top: -95px;
}
#pet:hover #eye-left {
transform: scale(1.5);
}
...
...
@@ -83,16 +93,30 @@ js = """
const pet = document.getElementById("pet");
const eyeLeft = document.getElementById("eye-left");
const eyeRight = document.getElementById("eye-right");
pet.addEventListener("mousemove", function(e) {
const x = e.offsetX;
const y = e.offsetY;
const eyeLeftX = x >= 100 ? 45 : 30;
const eyeRightX = x >= 100 ? 115 : 100;
const pupilLeftX = x >= 100 ? 47 : 32;
const pupilRightX = x >= 100 ? 117 : 102;
const eyeY = y >= 100 ? 45 : 32;
const pupilY = y >= 100 ? 47 : 34;
const handLeft = document.getElementById("hand-left");
const handRight = document.getElementById("hand-right");
function moveEyesAndArms(e) {
const rect = pet.getBoundingClientRect();
const centerX = rect.left + rect.width / 2;
const centerY = rect.top + rect.height / 2;
const x = e.pageX - centerX;
const y = e.pageY - centerY;
const angle = Math.atan2(y, x);
const eyeDistance = Math.min(Math.sqrt(x * x + y * y) / 50, 1.5);
const pupilDistance = Math.min(Math.sqrt(x * x + y * y) / 15, 0.5);
const armDistance = Math.min(Math.sqrt(x * x + y * y) / 30, 1);
const armRotation = Math.atan2(y, x);
const eyeLeftX = 50 + Math.cos(angle) * 45 * eyeDistance;
const eyeRightX = 115 + Math.cos(angle) * 45 * eyeDistance;
const pupilLeftX = 50 + Math.cos(angle) * 17 * pupilDistance;
const pupilRightX = 116 + Math.cos(angle) * 17 * pupilDistance;
const eyeY = 50 + Math.sin(angle) * 45 * eyeDistance;
const pupilY = 50 + Math.sin(angle) * 17 * pupilDistance;
const handLeftY = 50 + Math.sin(armRotation) * 30 * armDistance;
const handRightY = 50 + Math.sin(armRotation) * 30 * armDistance;
const handLeftX = -20 + Math.cos(armRotation) * 30 * armDistance;
const handRightX = 100 + Math.cos(armRotation) * 30 * armDistance;
eyeLeft.style.left = eyeLeftX + "px";
eyeRight.style.left = eyeRightX + "px";
eyeLeft.style.top = eyeY + "px";
...
...
@@ -101,7 +125,11 @@ pet.addEventListener("mousemove", function(e) {
eyeRight.querySelector("#pupil-right").style.left = pupilRightX + "px";
eyeLeft.querySelector("#pupil-left").style.top = pupilY + "px";
eyeRight.querySelector("#pupil-right").style.top = pupilY + "px";
});
handLeft.style.transform = "translateY(-50%) rotate(" + armRotation + "rad) translateY(" + handLeftY + "px) translateX(" + handLeftX + "px)";
handRight.style.transform = "translateY(-50%) rotate(" + armRotation + "rad) translateY(" + handRightY + "px) translateX(" + handRightX + "px)";
}
pet.addEventListener("mousemove", moveEyesAndArms);
</script>
"""
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录