Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
Move the ring to braid
css
body { margin: 0; overflow: hidden; background-color: #1F1F1F; } svg { width: 95vw; height: 95vh; } .mask-yes { fill: none; stroke: white; stroke-width: 14; } .mask-no { fill: none; stroke: black; stroke-width: 16; } .mask-block { fill: black; } .mask-frame { fill: none; stroke: black; stroke-width: 20; } .thread { fill: none; stroke-width: 14; } #grow > :nth-child(3n+1) .thread , .green { stroke: #008080; } #grow > :nth-child(3n+2) .thread , .red { stroke: #ff0000; } #grow > :nth-child(3n) .thread , .gold { stroke: #ffcc00; } .shadow-line { fill: url(#lline); } .shadow-upper { fill: url(#rstart1); } .shadow-lower { fill: url(#rstart2); } .light { fill: #fff; opacity: 0.65; } #end > g { display: none; } #end > .active { display: inline; }
JavaScript
const body = document.querySelector('svg'); const grow = document.querySelector('#grow'); const end = document.querySelector('#end'); const ring = document.querySelector('#ring'); const colors = ['green', 'gold', 'red']; let followRing = 170; let followMouse = 0; const mod = (n, d) => ((n % d) + d) % d function braid (newCount) { const count = grow.children.length; if (newCount === count) return; if (newCount < count) { for(let i = newCount; i < count; i++) { const g = grow.children[i]; if (grow.children[i]) grow.removeChild(g); } } else { for(let i = count; i < newCount; i++) { const g = document.createElementNS("http://www.w3.org/2000/svg", 'g'); grow.append(g); if (mod(i, 2)) { g.outerHTML = `
` } else { g.outerHTML = `
` } } } end.setAttribute('transform', `translate(${newCount * 10 - 60})`); for (let [i, g] of [...end.children].entries()) { g.classList.toggle('active', (newCount + i + 1) % 2); for (let thread of g.querySelectorAll('.thread')) { const base = parseFloat(thread.dataset.color); colors.forEach(c => thread.classList.remove(c)); thread.classList.add(colors[mod(base + Math.floor(newCount / 2), 3)]); } } } const follow = (event) => { const mx = body.getScreenCTM().inverse(); let x = new DOMPoint(event.clientX, event.clientY).matrixTransform(mx).x; x = Math.max(x, 105); x = Math.min(x, 585); ring.setAttribute('transform', `translate(${followRing + x - followMouse})`); braid(Math.floor((x - 105) / 10)); } ring.addEventListener('mousedown', (event) => { const mx = body.getScreenCTM().inverse(); followMouse = new DOMPoint(event.clientX, event.clientY).matrixTransform(mx).x; body.addEventListener('mousemove', follow); }); body.addEventListener('mouseup', () => { body.removeEventListener('mousemove', follow); followRing = 110 + grow.children.length * 10; ring.setAttribute('transform', `translate(${followRing})`); });
粒子
时间
文字
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号