Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8825767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:57:31+00:00 2026-06-14T06:57:31+00:00

Is there a way to draw shape (Rectangle) using Raphael like this? http://devfiles.myopera.com/articles/649/example3.html I

  • 0

Is there a way to draw shape (Rectangle) using Raphael like this?

http://devfiles.myopera.com/articles/649/example3.html

I tried below code but it didn’t do the trick because the rectangle shape appears only after ((onmouseup)) Event

Unlike the desired example above with mouse click and hold, on which the shape starts as a point, the size of the shape then changes as the user moves the mouse until the user releases the mouse the shape becomes permanent

$("#div1").mousedown(function(e) {

    var offset = $("#div1").offset();
    mouseDownX = e.pageX - offset.left;
    mouseDownY = e.pageY - offset.top;

});

$("#div1").mouseup(function(e) {
    var offset = $("#div1").offset();
    var upX = e.pageX - offset.left;
    var upY = e.pageY - offset.top;

    var width = upX - mouseDownX;
    var height = upY - mouseDownY;

    DrawRectangle(mouseDownX, mouseDownY, width, height);

});

function DrawRectangle(x, y, w, h) {

    var element = paper.rect(x, y, w, h);
    element.attr({
        fill : "gray",
        opacity : .5,
        stroke : "#F00"
    });
    $(element.node).attr('id', 'rct' + x + y);

    element.drag(move, start, up);
    element.click(function(e) {

        elemClicked = $(element.node).attr('id');

    });

}

Full example available in this fiddle
http://jsfiddle.net/XMyHz/26/

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T06:57:32+00:00Added an answer on June 14, 2026 at 6:57 am

    Here’s an example that uses Raphael to recreate the drawing example you linked to:
    http://jsfiddle.net/4Kdhz/1/

    As @Neil mentioned, you need to change the dimensions of the shape when you move the mouse, so the basic flow is this:

    onmousedown:

    1. Draw a 0 x 0 shape at the starting point.
    2. Add an event listener to onmousemove that executes a drawing function, doDraw().

    onmouseup:

    1. Remove the shape.
    2. Clear the onmousemove listener.

    doDraw():

    1. Get the starting point using the onmousedown coordinates.
    2. Calculate the x, y, width & height attributes of the shape and draw it.

    Note that with Raphael, a rectangle can’t have a negative width or height, hence changing the starting coordinates and multiplying the width and height by -1.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way to draw text in a DisplayObject or Shape using only
It there a way to draw a complex shape with an application like CorelDraw
Is there a way to draw an arc using points in JavaScript?? I need
Is there a way to draw custom Part tabs shape in an Eclipse RCP
Possible Duplicate: Draw Circle using css alone I would like to know if there
I just wondering is there way to make a tab like shape border? To
Is there a way to draw the lines in such a way that they
I was wondering if there is a way to draw an image but give
Is there any simple way how to draw obliquely strike through on TextView? Now
Is there a way to make the parent control draw over the children controls

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.