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:

  1. Find the corners of the image
  2. Make the area near the corners selectable
  3. Draw icons for the corners so it's obvious they are selectable
  4. Add click, drag and drop to the corners
  5. 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:

  1. Find the corners of the image
  2. Make the area near the corners selectable
  3. Draw icons for the corners so it's obvious they are selectable
  4. Add click, drag and drop to the corners
  5. 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 badges
Add a ment  | 

3 Answers 3

Reset to default 5 +50

I 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