Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
随机化眼睛颜色
css
* { -webkit-tap-highlight-color: rgba(0, 0, 0, 0); box-sizing: border-box; } html, body { background: #001c34; font-size: 10px; } #svg-defs { display: none; } section { width: 100vw; height: 100vh; display: flex; justify-content: center; align-items: center; } .container { width: 70vw; position: relative; max-width: 900px; display: flex; flex-direction: column; flex-wrap: wrap; } [class*="row"] { width: 100%; display: flex; justify-content: center; align-items: center; } .eye-element-container { cursor: pointer; width: 25.3333333333%; margin: -1% 4%; display: flex; justify-content: center; align-items: center; } .eye-element-container:hover .pupil { -webkit-transform: scale(0.7); transform: scale(0.7); } svg.eye-svg { width: 100%; } svg.eye-svg [id*="eye-clip-path"] path { transition: -webkit-transform 0.1s ease-in-out; transition: transform 0.1s ease-in-out; transition: transform 0.1s ease-in-out, -webkit-transform 0.1s ease-in-out; -webkit-transform: scaleY(1); transform: scaleY(1); -webkit-transform-origin: 50% 50%; transform-origin: 50% 50%; } svg.eye-svg.blink [id*="eye-clip-path"] path { -webkit-animation: blink 0.225s ease-in-out; animation: blink 0.225s ease-in-out; } svg.eye-svg * { pointer-events: none; } svg.eye-svg:active #eye-clip-path-1 path { -webkit-transform: scaleY(0); transform: scaleY(0); } svg.eye-svg:active #eye-clip-path-2 path { -webkit-transform: scaleY(0); transform: scaleY(0); } svg.eye-svg:active #eye-clip-path-3 path { -webkit-transform: scaleY(0); transform: scaleY(0); } svg.eye-svg:active #eye-clip-path-4 path { -webkit-transform: scaleY(0); transform: scaleY(0); } svg.eye-svg:active #eye-clip-path-5 path { -webkit-transform: scaleY(0); transform: scaleY(0); } svg.eye-svg:active #eye-clip-path-6 path { -webkit-transform: scaleY(0); transform: scaleY(0); } svg.eye-svg:active #eye-clip-path-7 path { -webkit-transform: scaleY(0); transform: scaleY(0); } svg.eye-svg:active #eye-clip-path-8 path { -webkit-transform: scaleY(0); transform: scaleY(0); } svg.eye-svg:active #eye-clip-path-9 path { -webkit-transform: scaleY(0); transform: scaleY(0); } svg.eye-svg:active #eye-clip-path-10 path { -webkit-transform: scaleY(0); transform: scaleY(0); } svg.eye-svg:active #eye-clip-path-11 path { -webkit-transform: scaleY(0); transform: scaleY(0); } svg.eye-svg:active #eye-clip-path-12 path { -webkit-transform: scaleY(0); transform: scaleY(0); } svg.eye-svg:active #eye-clip-path-13 path { -webkit-transform: scaleY(0); transform: scaleY(0); } svg.eye-svg:active #eye-clip-path-14 path { -webkit-transform: scaleY(0); transform: scaleY(0); } svg.eye-svg:active #eye-clip-path-15 path { -webkit-transform: scaleY(0); transform: scaleY(0); } .eye-moving-elements { -webkit-transform-origin: 50% 50%; transform-origin: 50% 50%; } .eye-moving-elements, .pupil-group, .highlight { transition: -webkit-transform .05s ease-out; transition: transform .05s ease-out; transition: transform .05s ease-out, -webkit-transform .05s ease-out; } .white-eye-background, .highlight { fill: #EFEAE4; } .iris { fill: #eb3e25; transition: fill .1s ease-in-out; } .iris.red { fill: #eb3e25; } .iris.blue { fill: #007ec3; } .iris.green { fill: #01a673; } .iris.yellow { fill: #fdc80a; } .pupil { fill: #001c34; -webkit-transform-origin: 50% 50%; transform-origin: 50% 50%; transition: -webkit-transform .25s ease-in-out; transition: transform .25s ease-in-out; transition: transform .25s ease-in-out, -webkit-transform .25s ease-in-out; pointer-events: none; } @-webkit-keyframes blink { 0% { -webkit-transform: scaleY(1); transform: scaleY(1); } 50% { -webkit-transform: scaleY(0); transform: scaleY(0); } 100% { -webkit-transform: scaleY(1); transform: scaleY(1); } } @keyframes blink { 0% { -webkit-transform: scaleY(1); transform: scaleY(1); } 50% { -webkit-transform: scaleY(0); transform: scaleY(0); } 100% { -webkit-transform: scaleY(1); transform: scaleY(1); } } .debug-panel { position: fixed; top: 0; left: 0; font-family: 'Helvetica', 'Arial', san-serif; color: white; padding: 10px; } button { display: inline-block; border: none; padding: 1rem 1.5rem; margin: 0; text-decoration: none; background: #002a4e; color: #ffffff; font-family: 'Helvetica', 'Arial', sans-serif; font-weight: bold; font-size: 1.4rem; cursor: pointer; text-align: center; transition: background 250ms ease-in-out, -webkit-transform 150ms ease; transition: background 250ms ease-in-out, transform 150ms ease; transition: background 250ms ease-in-out, transform 150ms ease, -webkit-transform 150ms ease; -webkit-appearance: none; -moz-appearance: none; position: fixed; bottom: 10px; left: 10px; } button:hover { background: #0053ba; } button:focus { outline: none; } button:active { -webkit-transform: scale(0.99); transform: scale(0.99); }
JavaScript
var windowH, windowW, containerW, containerH, mouseX, mouseY, irisColors = ['red', 'green', 'blue', 'yellow'], section = document.querySelector('section'), container = document.querySelector('.container'), eyeEls = document.querySelectorAll('.eye-element-container'), eyeSVGs = document.querySelectorAll('.eye-svg'), irisEls = document.querySelectorAll('.eye-moving-elements'), debugPanel = document.querySelector('.debug-panel'), generateColors = document.querySelector('.generate-new-colors'), eyeW, eyeH, zDist, xMove, yMove ; var debugMe = function() { var eyeOffsetX = eyeEls[4].offsetLeft + eyeW; var eyeOffsetY = eyeEls[4].offsetTop + eyeH; var eyePosX = ((containerW/2) - eyeOffsetX); var eyePosY = ((containerH/2) - eyeOffsetY); debugPanel.innerHTML = 'windowW: ' + windowW + '
' + 'windowH: ' + windowH + '
' + 'containerW: ' + containerW + '
' + 'containerH: ' + containerH + '
' + 'eyeW: ' + eyeW + '
' + 'eyeH: ' + eyeH + '
' + 'zDist: ' + zDist + '
' + 'eyeOffsetX: ' + eyeOffsetX + '
' + 'eyePosX: ' + eyePosX + '
' + 'eyeOffsetY: ' + eyeOffsetY + '
' + 'eyePosY: ' + eyePosY + '
' + 'mouseY: ' + mouseY + '
' + 'translateY: ' + (Math.atan((mouseY - eyePosY)/zDist)) + '
' + "yMove: " + yMove; } var getSizes = function() { windowW = window.innerWidth; windowH = window.innerHeight; containerW = container.offsetWidth; containerH = container.offsetHeight; eyeW = eyeEls[0].offsetWidth/2; eyeH = eyeEls[0].offsetHeight/2; zDist = eyeW*1.75; } var handleIrisMove = function(activate) { if (activate) { irisEls.forEach(function(i){ var myPosX = (i.closest('.eye-element-container').offsetLeft + eyeW) - (containerW/2); var myPosY = (i.closest('.eye-element-container').offsetTop + eyeH) - (containerH/2); xMove = Math.atan((mouseX - myPosX)/zDist)*.75; yMove = Math.atan((mouseY - myPosY)/zDist)*.5; i.setAttribute('style', 'transform: rotateY('+ xMove +'rad) rotateX(' + -1*yMove +'rad) translateZ(' + zDist + 'px)'); i.querySelector('.pupil-group').setAttribute('style', 'transform: rotateY('+ xMove*.35 +'rad) rotateX(' + -1*yMove*.35 +'rad) translateZ(' + zDist + 'px)'); i.querySelector('.highlight').setAttribute('style', 'transform: rotateY('+ xMove*.35 +'rad) rotateX(' + -1*yMove*.35 +'rad) translateZ(' + zDist + 'px)'); }); } if(!activate) { irisEls.forEach(function(i){ i.setAttribute('style', 'transform: rotateY(0rad) rotateX(0rad) translateZ(0px)'); i.querySelector('.pupil-group').setAttribute('style', 'transform: rotateY(0rad) rotateX(0rad) translateZ(0px)'); i.querySelector('.highlight').setAttribute('style', 'transform: rotateY(0rad) rotateX(0rad) translateZ(0px)'); }); } // debugMe(); } //Mouse Move Actions window.addEventListener('mousemove', function(e){ mouseX = e.clientX - windowW/2; mouseY = e.clientY - windowH/2; requestAnimationFrame(function(){ handleIrisMove(true); }); }, false); window.addEventListener('mouseout', function(e){ requestAnimationFrame(function(){ handleIrisMove(false); }); }, false); //Touch Move Actions section.addEventListener('touchmove', function(e){ e.preventDefault(); mouseX = e.touches[0].pageX - windowW/2; mouseY = e.touches[0].pageY - windowH/2; requestAnimationFrame(function(){ handleIrisMove(true); }); }, false); section.addEventListener('touchend', function(e){ e.preventDefault(); requestAnimationFrame(function(){ handleIrisMove(false); }); }, false); // Auto Blink Actions var randRange = function(min, max) { return Math.random() * (max - min) + min; } var blinkAction = function(el) { el.classList.add('blink'); el.addEventListener("webkitAnimationEnd", function(){ el.classList.remove('blink'); }, false); autoBlink(el); } var autoBlink = function() { setTimeout(function() { blinkAction(eyeSVGs[Math.floor(randRange(0, eyeSVGs.length))]); }, randRange(500, 4000)); } generateColors.addEventListener('click', function(){ irisEls.forEach(function(i){ var newColor = irisColors[Math.floor(Math.random()*irisColors.length)]; i.querySelector('.iris').classList = 'iris ' + newColor; }); console.log('test'); }, false); var changeEyeColor = function(el){ var myIris = this.querySelector('.iris'); var currentColor = myIris.classList.item(1); var newColor; var pickNewColor = function(){ newColor = irisColors[Math.floor(Math.random()*irisColors.length)] if (currentColor === newColor) { pickNewColor(); }; } pickNewColor(); myIris.className = ''; myIris.classList = 'iris ' + newColor; } eyeSVGs.forEach(function(i){ i.addEventListener('click', changeEyeColor); i.addEventListener('touchstart', changeEyeColor); }); //Window actions window.addEventListener('resize', getSizes); //Init Actions getSizes(); autoBlink();
粒子
时间
文字
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号