Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
esc
ins
del
caps
return
pause
pg up
shift
shift
↑
pg dn
ctrl
win
alt
alt
ctrl
←
↓
→
css
body { background-color: #625499; display: table-cell; height: 100vh; margin: 0; text-align: center; vertical-align: middle; width: 100vw; } .case { background-color: #463973; border-color: #2e2640; border-radius: 5px; border-style: solid; border-width: 8px 10px 15px 10px; display: inline-grid; grid-template-columns: repeat(36, 1fr); grid-template-rows: repeat(5, 1fr); height: 17em; padding: 5px; user-select: none; width: 60em; } .key { border-color: #382e59 #2e2640; border-radius: 2px; border-style: solid; border-width: 3px 5px 8px 5px; color: #bbadd9; display: block; font-family: sans-serif; font-size: 9px; font-weight: 800; grid-column-end: span 2; margin: 3px; padding-top: 2px; padding: 5px; text-align: center; text-transform: uppercase; transition: all 50ms ease-out; will-change: box-shadow, color, text-shadow; } .key:empty::before { content: attr(data-key); } .active { transform: perspective(1200px) translateZ(-90px); } .medium { grid-column-end: span 3; } .large { grid-column-end: span 4; } .xl { grid-column-end: span 5; } .xxl { grid-column-end: span 6; } .xxxl { grid-column-end: 7; } .huge { grid-column-end: span 12; }
JavaScript
const keysArr = [...document.querySelectorAll(".key")]; const getKey = (event) => { const parsedKey = event.key.toLowerCase().replace("\\", "\\\\"); const parsedCode = event.code.toLowerCase(); const element = document.querySelector(`[data-key="${parsedCode}"]`) || document.querySelector(`[data-key="${parsedKey}"]`); return element; }; const getEvent = () => {}; document.addEventListener("keydown", (event) => { const key = getKey(event); if (key) { key.classList.add("active"); } }); document.addEventListener("keyup", (event) => { const key = getKey(event); if (key) { key.classList.remove("active"); } }); document.addEventListener("mousedown", (event) => { if (event.target.dataset.key) { event.target.classList.add("active"); } }); document.addEventListener("mouseup", (event) => { if (event.target.dataset.key) { event.target.classList.remove("active"); } }); document.addEventListener("touchstart", (event) => { if (event.target.dataset.key) { event.target.classList.add("active"); } }); document.addEventListener("touchend", (event) => { if (event.target.dataset.key) { event.target.classList.remove("active"); } }); const animate = (element) => { const hueColor = Math.floor(Math.random() * (360 - 0 + 1)) + 0; const color = `hsla(${hueColor}, 100%, 50%, 50%)`; const textColor = `hsl(${hueColor}, 100%, 50%)`; const textShadow = `0 0 0.80em ${color}, 0 0 1.60em ${color}, 0 0 4em ${color}`; const boxShadow = `-3px 3px 4px ${color}, 3px -3px 4px ${color}, 3px 3px 4px ${color}, -3px -3px 4px ${color}, 0 0 10px ${color}`; const keyIndex = keysArr.indexOf(element); const animatedKeysRight = keysArr.slice(keyIndex); const animatedKeysLeft = keysArr.slice(0, keyIndex); const transitionHandler = (event) => { event.target.style.boxShadow = "none"; event.target.style.color = null; event.target.style.textShadow = "none"; event.target.removeEventListener("transitionend", transitionHandler); }; animatedKeysRight.forEach((keyEl, i) => { setTimeout(() => { keyEl.addEventListener("transitionend", transitionHandler); keyEl.style.boxShadow = boxShadow; keyEl.style.color = textColor; keyEl.style.textShadow = textShadow; }, i * 35); }); animatedKeysLeft.forEach((keyEl, j) => { const i = animatedKeysLeft.length - j; setTimeout(() => { keyEl.addEventListener("transitionend", transitionHandler); keyEl.style.boxShadow = boxShadow; keyEl.style.color = textColor; keyEl.style.textShadow = textShadow; }, i * 35); }); }; document.addEventListener("keydown", (event) => { const key = getKey(event); if (key) { animate(key); } }); document.addEventListener("click", (event) => { if (event.target.dataset.key) { animate(event.target); } }); window.addEventListener("load", () => { const key = document.querySelector(`[data-key="enter"]`); animate(key); });
粒子
时间
文字
hover
canvas
3d
游戏
音乐
火焰
水波
轮播图
鼠标跟随
动画
css
加载动画
导航
菜单
按钮
滑块
tab
弹出层
统计图
svg
×
Close
在线代码下载提示
开通在线代码永久免费下载,需支付20jQ币
开通后,在线代码模块中所有代码可终身免费下!
您已开通在线代码永久免费下载,关闭提示框后,点下载代码可直接下载!
您已经开通过在线代码永久免费下载
对不起,您的jQ币不足!可通过发布资源 或
直接充值获取jQ币
取消
开通下载
<!doctype html> <html> <head> <meta charset="utf-8"> <title>交互式键盘动画-jq22.com</title> <script src="https://www.jq22.com/jquery/jquery-1.10.2.js"></script> <style>
</style> </head> <body>
<script>
</script>
</body> </html>
2012-2021 jQuery插件库版权所有
jquery插件
|
jq22工具库
|
网页技术
|
广告合作
|
在线反馈
|
版权声明
沪ICP备13043785号-1
浙公网安备 33041102000314号