Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
css
* { box-sizing: border-box; } body { padding: 0; margin: 0; font-family: sans-serif; background-color: #63ec85; } .outer_wrapper { position: absolute; width: 100%; height: 100vh; overflow: hidden; } .wrapper { position: absolute; height: calc(100vh - 100px); width: 100%; top: 0; } .ground { position: absolute; bottom: 0; width: 100%; height: 150px; background-color: rgb(1, 143, 96); } .cat { position: absolute; bottom: 65px; left: 100px; height: 30px; width: 60px; transition: 1.5s; transform-origin: center; background-color: transparent; } /* body */ .body { position: absolute; height: 30px; width: 60px; } .face_left .body { animation: turn_body_left forwards 0.5s; } @keyframes turn_body_left { 0%,100% { transform: scale(1); } 50% { transform: scale(0.5, 1); } } .face_right .body { animation: turn_body_right forwards 0.5s; } @keyframes turn_body_right { 0%,100% { transform: scale(1); } 50% { transform: scale(0.5, 1); } } /* head */ .cat_head { position: absolute; height: 40px; width: 48px; right: -10px; top: -30px; transition: 0.5s; z-index: 50; } .first_pose .cat_head, .face_left .cat_head{ right: 22px; } /* tail */ .tail { position: absolute; top: -25px; height: 36px; width: 15px; animation: tail_motion forwards 2s; transform-origin: bottom right; } @keyframes tail_motion { 0%,100% { left: -5px; transform: rotate(0deg) scale(1); } 50% { left: -10px; transform: rotate(-50deg) scale(-1,1); } } .first_pose .tail , .face_left .tail { left: 45px; animation: tail_motion_alt forwards 2s; } @keyframes tail_motion_alt { 0%,100% { left: 45px; transform: rotate(0deg) scale(1); } 50% { left: 40px; transform: rotate(50deg) scale(-1,1); } } /* legs */ .leg { position: absolute; height: 20px; width: 10px; transform-origin: top center; } .front_legs, .back_legs { position: absolute; height: 30px; transition: 0.7s; } .front_legs { width: 30px; right: 0; } .back_legs { width: 25px; left: 0; } .face_left .leg svg { transform: scale(-1,1); } .face_right .front_legs{ right: 0; } .first_pose .front_legs, .face_left .front_legs{ right: 30px; } .face_right .back_legs{ left: 0; } .first_pose .back_legs, .face_left .back_legs{ left: 35px; } .one, .three { bottom: -15px; right: 0; } .two, .four { bottom: -15px; left: 0px; } .one.walk, .three.walk { animation: infinite 0.3s walk; } .two.walk, .four.walk { animation: infinite 0.3s walk_alt; } @keyframes walk { 0%,100% {transform: rotate(-10deg);} 50% {transform: rotate(10deg);} } @keyframes walk_alt { 0%,100% {transform: rotate(10deg);} 50% {transform: rotate(-10deg);} } /* jump */ .cat_wrapper { position: absolute; bottom: 0; } .cat_wrapper.jump .one { animation: infinite 0.3s walk; } .cat_wrapper.jump .two { animation: infinite 0.3s walk_alt; } .cat_wrapper.jump .three, .cat_wrapper.jump .four { animation: none; } .cat_wrapper.jump .cat.face_right .back_legs { transform-origin: center; transform: rotate(50deg); } .cat_wrapper.jump .cat.face_left .back_legs { transform-origin: center; transform: rotate(-50deg); } .cat_wrapper.jump .cat.face_right .front_legs { transform-origin: center; transform: rotate(-60deg); } .cat_wrapper.jump .cat.face_left .front_legs { transform-origin: center; transform: rotate(60deg); } .cat_wrapper.jump{ animation: jump forwards 1s; } @keyframes jump { 0%, 100% {bottom: 0px;} 50% {bottom: 200px;} } .jump .face_left{ animation: forwards 0.5s body_stand_left; transform-origin: right bottom; } .jump .face_right{ animation: forwards 0.5s body_stand_right; transform-origin: left bottom; } @keyframes body_stand_right { 0% {transform: rotate(0deg);} 100% {transform: rotate(-45deg);} } @keyframes body_stand_left { 0% {transform: rotate(0deg);} 100% {transform: rotate(45deg);} } svg { height: 100%; width: 100%; } polygon.eyes { fill: rgb(1, 143, 96); } polygon, path { fill: white; } .sign { position: absolute; color: white; bottom: 10px; right: 10px; font-size: 10px; } a { color: white; text-decoration: none; } a:hover { text-decoration: underline; }
JavaScript
function init() { const catWrapper = document.querySelector('.cat_wrapper') const wrapper = document.querySelector('.wrapper') const cat = document.querySelector('.cat') const head = document.querySelector('.cat_head') const legs = document.querySelectorAll('.leg') const pos = { x: null, y: null } const walk = () =>{ cat.classList.remove('first_pose') legs.forEach(leg=>leg.classList.add('walk')) } const handleMouseMotion = e =>{ pos.x = e.clientX pos.y = e.clientY walk() } const handleTouchMotion = e =>{ if (e.targetTouches) return pos.x = e.targetTouches[0].offsetX pos.y = e.targetTouches[0].offsetY walk() } const turnRight = () =>{ cat.style.left = `${pos.x - 90}px` cat.classList.remove('face_left') cat.classList.add('face_right') } const turnLeft = () =>{ cat.style.left = `${pos.x + 10}px` cat.classList.remove('face_right') cat.classList.add('face_left') } const decideTurnDirection = () =>{ cat.getBoundingClientRect().x < pos.x ? turnRight() : turnLeft() } const headMotion = () =>{ pos.y > (wrapper.clientHeight - 100) ? head.style.top = '-15px' : head.style.top = '-30px' } const jump = () =>{ catWrapper.classList.remove('jump') if (pos.y < (wrapper.clientHeight - 250)) { setTimeout(()=>{ catWrapper.classList.add('jump') },100) } } const decideStop = ()=>{ if (cat.classList.contains('face_right') && pos.x - 90 === cat.offsetLeft || cat.classList.contains('face_left') && pos.x + 10 === cat.offsetLeft) { legs.forEach(leg=>leg.classList.remove('walk')) } } setInterval(()=>{ if (!pos.x || !pos.y) return decideTurnDirection() headMotion() decideStop() },100) setInterval(()=>{ if (!pos.x || !pos.y) return jump() },1000) document.addEventListener('mousemove', handleMouseMotion) document.addEventListener('mousemove', handleTouchMotion) } window.addEventListener('DOMContentLoaded', init)
粒子
时间
文字
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号