Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
ymin:
ymax:
xmin:
xmax:
20
80
20
80
css
body { background: #1e88e5; } svg { overflow: visible; } rect { fill: white; } #theDefs { width: 0; height: 0; position: absolute; left: -100px; } path { stroke: black; stroke-width: 0.3px; } #wrap { position: absolute; height: 200px; width: 336px; margin: auto; top: 0; bottom: 0; left: 0; right: 0; } #svg_v { position: absolute; top: 0px; left: 0; } #svg_h { position: absolute; top: 32px; left: 136px; } text { text-anchor: middle; font-size: 8px; font-family: Helvetica; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; } svg text::selection { background: none; } .right { fill: gold; } .left { fill: skyBlue; } form{display:none;} input{width:2em;}
JavaScript
let m = {};//the mouse class DBSlider { constructor(elmt, type) { this.elmt = elmt; this.dragging = false; this.d ={}//the distance between the center of the thumb and the mouse on "mousedown" this.left = elmt.querySelector(".left"); this.right = elmt.querySelector(".right"); //the slider's thumbs this.thumbs = [this.left, this.right]; this.thisone;//the active thumb this.theother;//the other thumb this.type = type; //x for horizontal or y for vertical //the text element this.text = [ this.left.querySelector("text"), this.right.querySelector("text") ]; this.vals = [ //for the form theForm.querySelector(`#${this.type}min`), theForm.querySelector(`#${this.type}max`) ]; this.thumbs.map((th, i) => { let transf = th.getAttribute("transform"); // get the value of the transformation let p = transf.substring(10, transf.length - 1).split(","); //the thumb's center th.center = { x: Number(p[0]), y: Number(p[1]) }; th.addEventListener("mousedown", e => { m = oMousePosSVG(e, this.elmt); this.dragging = i + 1; this.thisone = th; this.theother = this.thumbs[this.dragging % 2]; this.d.x = th.center.x - m.x; this.d.y = th.center.y - m.y; }); }); this.elmt.addEventListener("mousemove", e => { if (this.dragging) { m = oMousePosSVG(e, this.elmt); // the position for the relevant coordinate let pos = m[this.type] + this.d[this.type]; // limit the thumb can not get out the track if (pos < 0) { pos = 0; } if (pos > 100) { pos = 100; } //reset the value of the center.x / center.y let c = this.thumbs[this.dragging - 1].center; //the c.x if the type is x or c.y if rge type is y c[this.type] = pos; // translate the group this.thumbs[this.dragging - 1].setAttributeNS( null, "transform", `translate(${c.x},${c.y})` ); // change the textContent of the text this.text[this.dragging - 1].textContent = Math.round(pos); //change the value of the corresponding input this.vals[this.dragging - 1].value = Math.round(pos); // get the distange between the thumbs let dist = this.right.center[this.type] - this.left.center[this.type]; // if the distance is < 0 you drag the other one if (dist < 0) { this.dragging = this.dragging % 2 + 1; } } }); this.elmt.addEventListener("mouseup", e => { m = oMousePosSVG(e, this.elmt); this.dragging = false; this.elmt.style.zIndex = 1; /* this.elmt.addEventListener("mouseleave", (e) => { m = oMousePosSVG(e,this.elmt); this.dragging = false; });*/ }); } } let slider = new DBSlider(svg_h, "x");//create the horizontal slider let slider1 = new DBSlider(svg_v, "y");//create the vertical slider function oMousePosSVG(e, svg) { var p = svg.createSVGPoint(); p.x = e.clientX; p.y = e.clientY; var ctm = svg.getScreenCTM().inverse(); var p = p.matrixTransform(ctm); return p; }
粒子
时间
文字
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号