admin管理员组文章数量:1307633
I want to let visitors scale the image using click-and-drag:
<html>
<body>
<svg>
<image>
Is there a JavaScript library that will help me?
I notice Raphael has click and drag methods but I will still have to write a lot of JS to:
- Find the corners of the image
- Make the area near the corners selectable
- Draw icons for the corners so it's obvious they are selectable
- Add click, drag and drop to the corners
- Update the dimensions of the image
I could do all that but it sounds time-consuming. Is there an open-source script I should use? Other suggestions?
I want to let visitors scale the image using click-and-drag:
<html>
<body>
<svg>
<image>
Is there a JavaScript library that will help me?
I notice Raphael has click and drag methods but I will still have to write a lot of JS to:
- Find the corners of the image
- Make the area near the corners selectable
- Draw icons for the corners so it's obvious they are selectable
- Add click, drag and drop to the corners
- Update the dimensions of the image
I could do all that but it sounds time-consuming. Is there an open-source script I should use? Other suggestions?
Share Improve this question edited Sep 5, 2011 at 3:48 ram1 asked Sep 4, 2011 at 18:06 ram1ram1 6,47010 gold badges42 silver badges46 bronze badges3 Answers
Reset to default 5 +50I found this solution at this post: Draggables and Resizables in SVG.
In the answer, you can find a jsfiddle link: http://jsfiddle/tmkfs/. You can resize the box by clicking and dragging the corner of the box. Hope this code could help you.
Not that I know of. I need to do the same thing and am surprised I haven't found a plugin or even an example of how to do this with Rahpeal.js yet. Since this seems like something a lot of people would want to do with SVG or Rapheal.js I'm suprised there isn't a built in way to do it (I would have thought scale + drag would do this but it wasn't as easy as it would have seemed).
I need this functionality so I've been building it out myself. I ran into a little snag (documented here: Raphael.js drag with scale causes weird jumping behavior) but just got it working. Once I'm finished, I can post my solution in a jsfiddle or on github when I'm done if you would like.
You should have a look to SvgKit It provides nice library to manipulate - generate svg's including event handling using javascript.
From official documentation:
Additions to the SVGKit object for event handling. In SVG it can be tricky to get from mouse coordinates to local coordinates. SVGEvent has routines to enable draggable items, rotatable items, and to prevent pan and zoom on items.
Event demos is here.
本文标签: javascriptHow to add clickanddrag to scale an image in an SVGStack Overflow
版权声明:本文标题:javascript - How to add click-and-drag to scale an image in an SVG? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741836749a2400263.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论