Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
Stroke width : {{ strokeWidth }}px
Precision : {{ strokePrecision }}px
{{ zoom }} %
Repeat : {{ repeat }}
css
body { margin: 0; width: 100%; height: 100%; font-family: 'Poppins', sans-serif; } #svg { position: absolute; z-index: 10; top: 0; right: 0; bottom: 0; left: 0; width: 100%; height: 100%; } .path { stroke: #000; stroke-width: 1px; fill: none; stroke-linejoin: round; stroke-linecap: round; } #overlay { position: absolute; z-index: 20; top: 0; right: 0; bottom: 0; left: 0; cursor: crosshair; } /* toolbar */ #toolbar { display: flex; position: fixed; z-index: 30; width: 100%; height: 40px; line-height: 40px; background: #f0f0f0; box-shadow: 0 2px 4px #c0c0c0; justify-content: center; } #toolbar>* { margin: 0; line-height: 40px; } .tbtn { position: relative; cursor: pointer; transition: all 0.3s; background: rgba(255, 255, 255, 0); padding: 0 15px; } .tbtn:hover { background: rgba(255, 255, 255, 0.7); } .ibtn { font-size: 20px; line-height: 40px; color: #ccc; } .tbtn:hover .ibtn { color: #555; } .itbtn.active { color: #666; } .tbtn:hover .ibtn.active { color: #333; } .toggle { position: absolute; z-index: 25; box-sizing: border-box; background: #fff; margin-top: 10px; padding: 10px; border-radius: 4px; box-shadow: 2px 2px 4px #555; text-align: left; line-height: initial; animation-duration: 0.2s; } #zoom-info { padding: 0 5px; font-size: 14px; } #stroke { width: 200px; margin-left: -90px; } #layer { width: 200px; margin-left: -160px; } /* toolbar - color */ #color { margin: 10px 0; width: 20px; height: 20px; border-radius: 50%; box-shadow: 1px 1px 3px #888; cursor: pointer; } .colors { list-style: none; width: 254px; margin-left: -117px; } .colors li { float: left; margin: 3px; width: 20px; height: 20px; cursor: pointer; border: 1px solid #ccc; box-sizing: border-box; } .colors li.active { border-color: #000; }
JavaScript
const palette = [ "#9BDAF3","#D8CCF4","#FAC2BB","#F8CD94","#9EDDDD","#FBE491","#FFC4E4","#C7E59A","#D0D3D6", "#34B3E4","#A589D9","#F16D64","#F59640","#35BEC1","#F3C746","#F371AF","#95C753","#A0A3A6", "#008CC9","#7C5BBB","#DD2E1F","#EC640C","#009EA5","#E6A700","#E2247F","#60AA14","#737679", "#005E93","#573B93","#A40F1C","#AF4104","#00727D","#AA7D00","#B10C5C","#3B7511","#000000" ]; Vue.component('switch-btn', { props: ['id', 'label', 'value'], template: '#switchBtn', }); new Vue({ el: '#app', data: { strokeWidth: 1, strokeColor: '#008CC9', strokePrecision: 100, repeat: 7, width: 0, height: 0, cx: 0, cy: 0, layer: { mirror: true, repeat: 7, elements: [], }, current: { type: '', points: [], }, viewBox: null, zoom: 100, palette, showPalette: false, showStroke: false, showLayer: false, showMarks: true, }, watch: { strokeColor(value) { this.current.stroke = value; }, repeat(value) { this.layer.repeat = parseInt(value); }, showPalette(value) { if (value) { this.showStroke = false; this.showLayer = false; } }, showStroke(value) { if (value) { this.showPalette = false; this.showLayer = false; } }, showLayer(value) { if (value) { this.showPalette = false; this.showStroke = false; } } }, computed: { transform() { return this.translate(this.cx, this.cy); } }, created() { this.line = d3.line().curve(d3.curveBasis); }, mounted() { this.onResize(); window.addEventListener('resize', this.onResize); document.addEventListener('keyup', this.onKeyUp); }, mixins: [ mouseMixin() ], methods: { pathd(points) { return this.line(points); }, resetPath(e) { e.type = 'path'; e.points = []; e.stroke = this.strokeColor; e.strokeWidth = this.strokeWidth; }, /** * input events */ onInputStart(e) { this.showPalette = this.showStroke = this.showLayer = false; this.resetPath(this.current); this.x0 = this.x1; this.y0 = this.y1; this.current.points = [[this.x1, this.y1], [this.x1, this.y1]]; }, onInputMove(e) { let points = this.current.points; const dx = this.x1 - this.x0; const dy = this.y1 - this.y0; if (dx * dx + dy * dy > this.strokePrecision) points.push([this.x0 = this.x1, this.y0 = this.y1]); else this.$set(points, points.length-1, [this.x1, this.y1]); }, onInputEnd(e) { if (this.current.points.length>1) { this.layer.elements.push({ ...this.current, d: this.pathd(this.current.points) }); } this.resetPath(this.current); }, updateInputCoords(e) { this.x1 = this.vbX + this.currX * (this.vbW / this.width) - this.cx; this.y1 = this.vbY + this.currY * (this.vbH / this.height) - this.cy; }, /** * misc events */ onResize() { const r = this.$refs.svg.getBoundingClientRect(); this.width = r.width; this.height = r.height; this.cx = r.width / 2; this.cy = r.height / 2; this.updateViewBox(); }, onMouseWheel(e) { e.preventDefault(); if (e.deltaY < 0) this.zoomIn(); else this.zoomOut(); }, zoomIn() { this.zoom = Math.min(195, this.zoom + 5); this.updateViewBox(); }, zoomOut() { this.zoom = Math.max(5, this.zoom - 5); this.updateViewBox(); }, updateViewBox() { this.vbX = ((this.width * this.zoom / 100) - this.width) / 2; this.vbY = ((this.height * this.zoom / 100) - this.height) / 2; this.vbW = this.width - 2 * this.vbX; this.vbH = this.height - 2 * this.vbY; this.viewBox = this.vbX + ' ' + this.vbY + ' ' + this.vbW + ' ' + this.vbH; }, onKeyUp(e) { if (e.ctrlKey && e.keyCode==90) { this.onCtrlZ(); } }, onCtrlZ() { this.layer.elements.pop(); }, onReset() { this.layer.elements = []; }, /** * misc */ estyle(e) { return { stroke: e.stroke, 'stroke-width': e.strokeWidth, }; }, rotatePart(i, n) { return this.rotate(i * 360 / n); }, translate(x, y) { return 'translate(' + x + ', ' + y + ')'; }, rotate(r) { return 'rotate(' + r + ')'; } } }); function mouseMixin() { return { created() { this.mouseDown = false; this.touchDown = false; }, methods: { /** * mouse events */ onMouseDown(e) { if (e.which == 1) { this.mouseDown = true; this.updateMouseCoords(e); this.onInputStart(e); } }, onMouseMove(e) { if (this.mouseDown) { this.prevX = this.currX; this.prevY = this.currY; this.updateMouseCoords(e); this.onInputMove(e); } }, onMouseEnd(e) { if (this.mouseDown) { this.mouseDown = false; this.onInputEnd(e); } }, updateMouseCoords(e) { var clientRect = e.target.getBoundingClientRect(); this.currX = e.clientX - clientRect.left; this.currY = e.clientY - clientRect.top; this.updateInputCoords(e); }, /** * touch events */ onTouchStart(e) { e.preventDefault(); this.touchDown = true; this.updateTouchCoords(e); this.onInputStart(e); }, onTouchMove(e) { if (this.touchDown) { this.prevX = this.currX; this.prevY = this.currY; this.updateTouchCoords(e); this.onInputMove(e); } }, onTouchEnd(e) { if (this.touchDown) { e.preventDefault(); this.touchDown = false; this.onInputEnd(e); } }, updateTouchCoords(e) { var clientRect = e.target.getBoundingClientRect(); this.currX = e.changedTouches[0].clientX - clientRect.left; this.currY = e.changedTouches[0].clientY - clientRect.top; this.updateInputCoords(e); } } }; } function rnd(max, negative) { return negative ? Math.random() * 2 * max - max : Math.random() * max; }
粒子
时间
文字
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号