Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
tilt
css
* { margin: 0; padding: 0; box-sizing: border-box; } html { width: 100%; height: 100%; font-size: 18px; } body { width: 100%; min-height: 100%; display: flex; justify-content: center; align-items: center; background: #0E0027; position: relative; overflow: hidden; } .grid { position: absolute; width: 100vw; height: 100vh; background: #0E0027; display: grid; grid-template-columns: repeat(10, 1fr); grid-template-rows: repeat(10, 1fr); grid-gap: 1px; z-index: 0; overflow: hidden; } .grid .grid-highlight { position: absolute; width: 100%; height: 100%; background: radial-gradient(circle, rgba(255, 255, 255, 0.3) 0%, #0e0027 50%); z-index: -1; } .grid .item { background: #0E0027; transition: background .25s ease; } .lamp { position: absolute; margin: auto; height: 50vh; width: 4vh; top: 0; bottom: 0; left: 0; border-radius: 2vh; background: #fff; z-index: 1; box-shadow: 0 0 1vh 0.5vh #c0e0fc, 0 0 2vh 1vh #c0e0fc, 0 0 5vh 1vh #90c8f9, 0 0 10vh 1vh #77bcf8, 0 0 15vh 1vh #5FB0F7, 0 0 20vh 1vh #5FB0F7, 0 0 25vh 1vh #5FB0F7, 0 0 50vh 1vh #5FB0F7; transition: box-shadow .5s ease; } .lamp--to-left { box-shadow: 0 0 1vh 0.5vh #c0e0fc, -1vh 0 2vh 1vh #c0e0fc, -4vh 0 5vh 1vh #90c8f9, -10vh 0 10vh 1vh #77bcf8, -13vh 0 15vh 1vh #5FB0F7, -15vh 0 20vh 1vh #5FB0F7, -25vh 0 25vh 0 #5FB0F7, -50vh 0 50vh 0 #5FB0F7; } .lamp--to-right { box-shadow: 0 0 1vh 0.5vh #c0e0fc, 1vh 0 2vh 1vh #c0e0fc, 4vh 0 5vh 1vh #90c8f9, 10vh 0 10vh 1vh #77bcf8, 13vh 0 15vh 1vh #5FB0F7, 15vh 0 20vh 1vh #5FB0F7, 25vh 0 25vh 0 #5FB0F7, 50vh 0 50vh 0 #5FB0F7; } .tilt-btn { position: fixed; right: 1rem; top: 1rem; padding: .5rem 1rem; display: block; background: #7527ff; color: #fff; transition: opacity .25s ease; cursor: pointer; } .tilt-btn--off { opacity: .6; text-decoration: line-through; } .tilt-btn:hover { opacity: 1; text-decoration: none; }
JavaScript
// move your mose to move the lamp console.clear(); let tilt = false; // tilt the lamp! let ready = false; const lamp = document.querySelectorAll('.lamp')[0]; const highlight = document.querySelectorAll('.grid-highlight')[0]; const tiltBtn = document.querySelectorAll('.tilt-btn')[0]; let transitionTime = 2; let ease = Power4.easeOut; let lastX, threshold = 50; const move = e => { if (!ready) return; let xPos = e.clientX; let offset = 0; if (tilt) { if (lastX < xPos - 1) { lamp.classList.remove('lamp--to-left'); lamp.classList.add('lamp--to-right'); offset = 200; } else if (lastX > xPos + 1) { lamp.classList.remove('lamp--to-right'); lamp.classList.add('lamp--to-left'); offset = -200; } else { lamp.classList.remove('lamp--to-right', 'lamp--to-left'); } } TweenMax.to(lamp, transitionTime, { x: xPos - lamp.offsetWidth / 2, ease: ease }); TweenMax.to(highlight, transitionTime, { x: (xPos - highlight.offsetWidth / 2) + offset, ease: ease }); lastX = xPos; } document.addEventListener('mousemove', move); tiltBtn.addEventListener('click', function() { if (tilt) { tilt = false; tiltBtn.classList.add('tilt-btn--off'); lamp.classList.remove('lamp--to-right', 'lamp--to-left'); } else { tilt = true; tiltBtn.classList.remove('tilt-btn--off'); } }); /* intro movement */ const intro = () => { let xPos = window.innerWidth / 2; const tl = new TimelineMax(); tl.set(lamp, {x: xPos}); tl.to(lamp, transitionTime, { x: (xPos * 1.8) - lamp.offsetWidth / 2, ease: ease }); tl.to(highlight, transitionTime, { x: (xPos * 1.8) - highlight.offsetWidth / 2, ease: ease }, `-=${transitionTime}`); tl.to(lamp, transitionTime, { x: (xPos * 0.5) - lamp.offsetWidth / 2, ease: ease }, `-=${transitionTime / 2}`); tl.to(highlight, transitionTime, { x: (xPos * 0.5) - highlight.offsetWidth / 2, ease: ease, onComplete: function() { ready = true; } }, `-=${transitionTime}`); lastX = xPos; } intro();
粒子
时间
文字
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号