- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我希望能够使用 Snap SVG 将一组集合作为一个组进行拖动。到目前为止,我只能将子集(矩形和文本框)作为一个项目进行拖动,但我想要实现的是集体“表格”是可拖动的,而其中的字段仍保留为单独的形状,因此我可以保持它们之间的联系正常工作。这可能吗?(编辑 - 我从 Raphael 重构为 Snap 并尝试将集合放入一个组中进行拖动)
这里是骗子的链接:http://plnkr.co/edit/9ewo0OcgThwB4KyMTxIL?p=preview
还有下面的代码:
// Code goes here
Snap.plugin( function( Snap, Element, Paper, global ) {
Paper.prototype.connection = function (obj1, obj2, line, bg) {
if (obj1.line && obj1.from && obj1.to) {
line = obj1;
obj1 = line.from;
obj2 = line.to;
}
var bb1 = obj1.getBBox(),
bb2 = obj2.getBBox(),
p = [{x: bb1.x + bb1.width / 2, y: bb1.y - 1},
{x: bb1.x + bb1.width / 2, y: bb1.y + bb1.height + 1},
{x: bb1.x - 1, y: bb1.y + bb1.height / 2},
{x: bb1.x + bb1.width + 1, y: bb1.y + bb1.height / 2},
{x: bb2.x + bb2.width / 2, y: bb2.y - 1},
{x: bb2.x + bb2.width / 2, y: bb2.y + bb2.height + 1},
{x: bb2.x - 1, y: bb2.y + bb2.height / 2},
{x: bb2.x + bb2.width + 1, y: bb2.y + bb2.height / 2}],
d = {}, dis = [];
for (var i = 0; i < 4; i++) {
for (var j = 4; j < 8; j++) {
var dx = Math.abs(p[i].x - p[j].x),
dy = Math.abs(p[i].y - p[j].y);
if ((i == j - 4) || (((i != 3 && j != 6) || p[i].x < p[j].x) && ((i != 2 && j != 7) || p[i].x > p[j].x) && ((i != 0 && j != 5) || p[i].y > p[j].y) && ((i != 1 && j != 4) || p[i].y < p[j].y))) {
dis.push(dx + dy);
d[dis[dis.length - 1]] = [i, j];
}
}
}
if (dis.length == 0) {
var res = [0, 4];
} else {
res = d[Math.min.apply(Math, dis)];
}
var x1 = p[res[0]].x,
y1 = p[res[0]].y,
x4 = p[res[1]].x,
y4 = p[res[1]].y;
dx = Math.max(Math.abs(x1 - x4) / 2, 10);
dy = Math.max(Math.abs(y1 - y4) / 2, 10);
var x2 = [x1, x1, x1 - dx, x1 + dx][res[0]].toFixed(3),
y2 = [y1 - dy, y1 + dy, y1, y1][res[0]].toFixed(3),
x3 = [0, 0, 0, 0, x4, x4, x4 - dx, x4 + dx][res[1]].toFixed(3),
y3 = [0, 0, 0, 0, y1 + dy, y1 - dy, y4, y4][res[1]].toFixed(3);
var path = "M" + x1.toFixed(3) + "," + y1.toFixed(3) + "C" + [ x2, y2, x3, y3, x4.toFixed(3), y4.toFixed(3)].join();
if (line && line.line) {
line.bg && line.bg.attr({path: path});
line.line.attr({path: path});
} else {
var color = "#000";
return {
bg: bg && bg.split && this.path(path).attr({stroke: bg.split("|")[0], fill: "none", "stroke-width": bg.split("|")[1] || 3}),
line: this.path(path).attr({stroke: color, fill: "none"}),
from: obj1,
to: obj2
};
}
}
});
var el;
(function () {
var color, i, ii, tempS, tempT;
var dragger = function () {
this.data("ox", this.attr("x"));
this.data("oy", this.attr("y"));
if (this.type != "text") this.animate({"fill-opacity": .2}, 500);
//this.pair.ox = this.pair.attr("x");
this.pair.data("ox", this.pair.attr("x"));
//this.pair.oy = this.pair.attr("y");
this.pair.data("oy", this.pair.attr("y"));
if (this.pair.type != "text") this.pair.animate({"fill-opacity": .2}, 500);
},
move = function (dx, dy) {
var att = {x: parseInt(this.data("ox")) + dx, y: parseInt( this.data("oy")) + dy};
this.attr(att);
//att = {x: this.pair.ox + dx, y: this.pair.oy + dy};
att = {x: this.pair.data("oy") + dx, y: this.pair.data("oy") + dy};
this.pair.attr(att);
for (var i = connections.length; i--;) {
s.connection(connections[i]);
}
},
up = function () {
if (this.type != "text") this.animate({"fill-opacity": 0}, 500);
// Fade paired element on mouse up
if (this.pair.type != "text") this.pair.animate({"fill-opacity": 0}, 500);
},
s = Snap("#svgout"),
connections = [],
shapes = [ // Users
s.rect(250, 80, 80, 20),
s.rect(250, 100, 80, 20),
s.rect(250, 120, 80, 20),
// Groups
s.rect(380, 80, 80, 20),
s.rect(380, 100, 80, 20),
s.rect(380, 120, 80, 20)
],
texts = [
s.text(290, 90, "Users"), //0
s.text(290, 110, "id"), //1
s.text(290, 130, "name"), //2
s.text(420, 90, "Groups"), //3
s.text(420, 110, "id"), //4
s.text(420, 130, "owner") //5
];
for (var i = 0, ii = shapes.length; i < ii; i++) {
color = "grey";
tempS = shapes[i].attr({fill: color, stroke: color, "fill-opacity": 0, "stroke-width": 2, cursor: "move"});
tempT = texts[i].attr({fill: color, stroke: "none", "font-size": 15, cursor: "move"});
//shapes[i].drag(move, dragger, up);
//texts[i].drag(move, dragger, up);
// Associate the elements
//tempS.pair = tempT;
//tempT.pair = tempS;
}
connections.push(s.connection(shapes[1], shapes[5]));
var group1 = s.g(shapes[0], shapes[1], shapes[2], texts[0], texts[1], texts[2]);
group1.drag(move, dragger, up);
})();
最佳答案
使用 Snap 会更容易一些,因为您根本不需要担心设置。 graffle/转换代码工作正常,但它只适用于矩形和圆形,因此实际上看起来可能有点复杂,但我们可以让它适用于通过变换拖动的任何形状。
为了做到这一点,我们需要创建一个插件来获取一个边界框来说明其变换,我不认为 Snap 目前会这样做(尽管有方法 getBBox(1) 我不认为这是正如我想象的那样工作)
因此,最初需要一个插件来获取转换后的bbox(可能有更有效的方法,但只是做一个快速解决方案)...
Element.prototype.getTransformedBB = function() {
var bb = this.getBBox(1);
var t = this.node.getTransformToElement( this.paper.node );
var m = Snap.matrix( t );
var obj = { x: m.x( bb.x, bb.y ), y: m.y( bb.x, bb.y ), x2: m.x( bb.x2, bb.y2 ), y2: m.y( bb.x2, bb.y2 ),
cx: m.x( bb.cx, bb.cy ), cy: m.y( bb.cy, bb.cy ) }
obj['width'] = obj.x2 - obj.x
obj['height'] = obj.y2 - obj.y
return obj;
};
然后在连接代码中使用 getTransformedBB,而不是 getBBox()...
var bb1 = obj1.getTransformedBB(),
bb2 = obj2.getTransformedBB(),
现在您正在使用 Snap,您可以使用适用于所有形状的简单拖动处理程序...
var dragger = function () {
this.data('origTransform', this.transform().local )
this.animate({"fill-opacity": .5}, 500);
},
move = function (dx, dy) {
this.attr({ transform: this.data('origTransform') + (this.data('origTransform') ? "T" : "t") + [dx, dy]})
for (var i = connections.length; i--;) {
s.connection(connections[i]);
}
},
up = function () {
this.animate({"fill-opacity": 1}, 500);
},
如果您只使用矩形,您可能不需要 TransformedBB 的东西,但我认为这个解决方案可能适用于更奇怪的组情况。
来自组顶部的连接有点奇怪,不确定这是否是原始代码的错误或什么,但如果需要,您可以通过在矩形上放置白色填充并制作来解决它确保这是在连接后添加的。
关于javascript - 捕捉 svg 拖动一组集合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34280545/
我正在使用 gridstack 来显示我的小部件。拖动和调整大小适用于 gridstack 卡,但当我将卡拖到底部时,卡的容器不会滚动。我想在拖动卡片时滚动那个容器。该容器只是一个 div 元素,所有
我目前正在构建一个多个处理的 slider 小部件,并且目前正在实现手势检测器。我有一个问题,如果您用第二根手指触摸/拖动屏幕,检测器会识别它并调用 onDragUpdate 函数,这是我试图禁用的功
我是 AngularJS 的新手,我对当前的项目有点压力,这就是我在这里问的原因。 我看到 AngularJS 有 ng-dragstart 事件( http://docs.ng.dart.ant.c
关于缩放大图像和平移有什么建议吗?最好内联在页面上。 我一直在使用PanoJS(又名GSV2),但是现在越来越多的人使用iPhone/iPad/Android类型的设备,这个库要么太慢,要么旧版本不支
我在尝试拖动 JPanel 时遇到问题。如果我纯粹在 MouseDragged 中将其实现为: public void mouseDragged(MouseEvent me) { me.getS
我有一个需要与屏幕底部对齐的 ImageButton,当我单击并拖动它时,它会随着我的手指移动一定距离,超过该距离它不会远离原点,而是继续跟随我的手指从原点开始的方向。 当我松手时,按钮必须滑回原点。
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 9 年前。 Improve this qu
我需要一个解决方案来实现拖动和缩放,在不使用矩阵的情况下围绕屏幕 onTouch 事件路由 ImageView。我搜索了很多但所有答案都是用矩阵完成的,因为我在屏幕矩阵中有多个对象不适合我,我想拖动和
我需要一些帮助来拖动 UIView 以显示主视图下方的菜单 View 。 我有两个 UIView。menuView - 包括菜单按钮和标签 和 mainView - 位于 menuView 之上。 我
谷歌地图即使设为 true 也不可拖动/拖动。 重现步骤:在新选项卡中加载带有 map 的页面,检查并在不执行任何操作的情况下转到移动 View 。现在在移动 View 中左右上下拖动 map ,它将
我在绘制和缩放 ImageView 时遇到问题。请帮帮我.. 当我画一些东西然后拖动或缩放图像时 - 绘图保留在原处,如您在屏幕截图中所见。而且我只需要简单地在图片上绘图,并且可以缩放和拖动这张图片。
所以我试图模拟鼠标左键单击和鼠标左键释放来执行一些自动拖放操作。 它目前在 C# Winforms(是的,winforms :|)中并且有点笨拙。 基本上,一旦发送了点击,我希望它根据 Kinect
我有一个巨大的 HTML5 Canvas,我希望它像谷歌地图一样工作:用户可以拖动它并始终只看到它的一小部分(屏幕大小)。它只呈现您在屏幕上可以看到的部分。我该怎么做?你有想法吗? 最佳答案 2 个简
我有以下拖放应用程序代码,它在桌面上按预期工作,但是当我想在移动设备上使用该应用程序时,拖动事件无法按预期工作。我知道触摸事件是必需的,但我不确定如何设置它们和实现这些功能。 .object
我正在使用 react-leaflet map ,我用状态改变了很多 map 属性,但是当使用状态来改变拖动属性时它不起作用。 { this.map = map}}
我知道我可以轻松地允许用户在OpenLayers中选择多个功能/几何图形,但是随后我希望使用户能够轻松地同时拖动/移动所有选定的功能。 使用ModifyFeature控件一次只能移动一个要素...是否
我有一个 Windows Phone 运行时应用程序,我使用 xaml 在 map 上显示图钉。 当我拖动 map 时,控件试图保持在相同位置时会出现一些滞后。 任何帮助,将不胜感
我通常不会提出此类问题/答案,但我想我会这样做,因为我已经看到这个问题被问了 20 多次,但没有一个答案真正有效。简而言之,问题是,如果您在可拖动 jQuery 项目内的任何位置有可滚动内容(over
我确信一定有一种简单的方法可以做到这一点,但到目前为止,我已经花了很长时间在各种兔子洞中没有成功。 我有一个支持拖放的 Collection View 。被拖动的单元格有 UIImageView在 c
如何在两个virtualtreeview之间复制以复制所有列,而不仅仅是第一列? 复制前: 复制后: 最佳答案 树控件不保存任何数据。它不包含要显示的列数据,因此无法复制它。而是,当树控件想要显示任何
我是一名优秀的程序员,十分优秀!