简体   繁体   English

svg.js:使用鼠标选择元素

[英]svg.js: select elements with mouse

I am using svg.js to draw a svg with several boxes like this: 我正在使用svg.js绘制带有几个框的svg,如下所示:

在此处输入图片说明

The SVG contents look like this: SVG内容如下所示:

<g id="1">
  <title>Box 1</title>
  <polygon id="target_1" fill="#fdb8d4" points="70 10 100 10 100 40 70 40"/>
</g>

I'd like to select one or multiple boxes on mouse down, move and release, eg like visualized in this image: 我想在鼠标按下,移动和释放时选择一个或多个框,例如,如这张图所示:

在此处输入图片说明

I found the select plugin for svg.js, but it seams not to do the job. 我找到了svg.js的选择插件 ,但它似乎无法完成这项工作。

Can someone point me into the right direction? 有人可以指出我正确的方向吗? Is there some functionality already existing or do i need to implement it from scratch? 是否已经存在某些功能,或者我需要从头开始实现它?

Simple fiddle here . 这里简单的摆弄。

Found a plugin called nuSelectable . 找到了一个名为nuSelectable的插件。

You can use it like so JSFIDDLE 您可以这样使用它,例如JSFIDDLE

<div class="svgContainer">
  <svg height="150" width="150" class="item">
    <circle cx="60" cy="60" r="50" style="fill: blue; stroke: black; stroke-width: 2px;" />
  </svg>
  <svg height="150" width="150" class="item">
    <circle cx="60" cy="60" r="50" style="fill: blue; stroke: black; stroke-width: 2px;" />
  </svg>
</div>

JS initialization code: JS初始化代码:

$(function() {
  $('.svgContainer').nuSelectable({
    items: '.item',
    selectionClass: 'nu-selection-box',
    selectedClass: 'nu-selected',
    autoRefresh: true
  });
});

PS The selection box for some reason is not visible in the fiddle, but in chrome is visible, feel free to style it using the class .nu-selection-box . PS出于某种原因,选择框在小提琴中不可见,但在chrome中可见,请随时使用.nu-selection-box类对其进行样式.nu-selection-box

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM