Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
Rotating SVG-Cursor
css
@import url("https://fonts.googleapis.com/css?family=Dosis:300,400,700"); body { font-family: 'Dosis', sans-serif; margin: 0; padding: 0; height: 100vh; width: 100vw; display: -webkit-box; display: -ms-flexbox; display: flex; -webkit-box-orient: vertical; -webkit-box-direction: normal; -ms-flex-direction: column; flex-direction: column; -webkit-box-align: center; -ms-flex-align: center; align-items: center; -webkit-box-pack: center; -ms-flex-pack: center; justify-content: center; cursor: none; } body * { cursor: inherit; } #cursor { position: absolute; left: -28px; top: -34px; will-change: transform; -webkit-transform: translate(-999px, -999px); transform: translate(-999px, -999px); pointer-events: none; } #cursor img { will-change: transform; -webkit-transition: -webkit-transform .1s linear; transition: -webkit-transform .1s linear; transition: transform .1s linear; transition: transform .1s linear, -webkit-transform .1s linear; } @-webkit-keyframes color-blink { 0% { color: #eb3424; } 14% { color: #f2a03a; } 28% { color: #f8fd53; } 42% { color: #7bec4b; } 56% { color: #74fbe4; } 70% { color: #0035f5; } 84% { color: #b337f6; } 100% { color: #b337f6; } } @keyframes color-blink { 0% { color: #eb3424; } 14% { color: #f2a03a; } 28% { color: #f8fd53; } 42% { color: #7bec4b; } 56% { color: #74fbe4; } 70% { color: #0035f5; } 84% { color: #b337f6; } 100% { color: #b337f6; } } header { text-align: center; } header img { opacity: .3; } header h1 { margin-top: 3rem; margin-bottom: 0; } header a { font-weight: 600; color: currentcolor; text-decoration: none; } header a:first-of-type { -webkit-animation: 2s infinite alternate color-blink; animation: 2s infinite alternate color-blink; }
JavaScript
'use strict'; // Because of a WebKit-Issue which renders (even SVG) cursors blurry on Retina-Displays I decided to go for a solution which renders the cursor within a custom
. var rotatingCursor = function () { /* Local Variables */ var INTERVAL_POSITION = 5; var INTERVAL_ROTATION = 100; var lastCursorPos = { x: -999, y: -999 }; var currentCursorPos = { x: -999, y: -999 }; var lastCursorAngle = 0, cursorAngle = 0; var cursorEl = undefined, cursorImageEl = undefined; /* Local Functions */ // NOTE: I am transform two different elements here because so I can only animate the rotation with 'transition-property: transform'. function setCurrentCursorProps() { // Apply translation (set to actual cursor position) cursorEl.style.transform = 'translate(' + currentCursorPos.x + 'px, ' + currentCursorPos.y + 'px)'; // Ensure correct rotation transition direction while (Math.abs(lastCursorAngle - cursorAngle) > 180) { if (cursorAngle > lastCursorAngle) { cursorAngle -= 360; } else if (cursorAngle < lastCursorAngle) { cursorAngle += 360; } } // Apply rotation cursorImageEl.style.transform = 'rotate(' + (cursorAngle - 90) + 'deg)'; } function updateCursor() { window.addEventListener('mousemove', function (event) { currentCursorPos = { x: event.clientX, y: event.clientY }; }); // Interval for updating cursor-position setInterval(setCurrentCursorProps, INTERVAL_POSITION); // Interval for updating cursor-rotation setInterval(function () { var delt = { x: lastCursorPos.x - currentCursorPos.x, y: lastCursorPos.y - currentCursorPos.y }; if (Math.abs(delt.x) < 3 && Math.abs(delt.y) < 3) return; cursorAngle = Math.atan2(delt.y, delt.x) * 180 / Math.PI; setCurrentCursorProps(); lastCursorPos = currentCursorPos; lastCursorAngle = cursorAngle; }, INTERVAL_ROTATION); } /* Public Functions */ return { 'initialize': function initialize() { cursorEl = document.querySelector('#cursor'); cursorImageEl = document.querySelector('#cursor > img'); updateCursor(); } }; }(); document.addEventListener('DOMContentLoaded', rotatingCursor.initialize);
粒子
时间
文字
hover
canvas
3d
游戏
音乐
火焰
水波
轮播图
鼠标跟随
动画
css
加载动画
导航
菜单
按钮
滑块
tab
弹出层
统计图
svg
×
Close
在线代码下载提示
开通在线代码永久免费下载,需支付20jQ币
开通后,在线代码模块中所有代码可终身免费下!
您已开通在线代码永久免费下载,关闭提示框后,点下载代码可直接下载!
您已经开通过在线代码永久免费下载
对不起,您的jQ币不足!可通过发布资源 或
直接充值获取jQ币
取消
开通下载
<!doctype html> <html> <head> <meta charset="utf-8"> <title>旋转的SVG光标-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号