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 8355603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:54:56+00:00 2026-06-09T09:54:56+00:00

Not sure exactly what to call it, but I am looking for a way

  • 0

Not sure exactly what to call it, but I am looking for a way to create a dotted outline/selection box effect via javascript/svg when you click and drag over an area, and then goes away on mouseUp (that could be added if it wasn’t an original part) .

A jQuery library would be nice if it exists. I’ve done some looking around, and haven’t found exactly what I am looking for.
I guess the theory would be get the coord from the first click, track the mouse coord moment and adjust the box accordingly.

But not writing it from scratch would be nice.

  • 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-09T09:54:58+00:00Added an answer on June 9, 2026 at 9:54 am

    Here’s a demo I made just for you 🙂

    Demo (Static): http://jsfiddle.net/HNH2f/1/

    Demo (Animated): http://jsfiddle.net/HNH2f/2/

    You can use CSS to control the visual style of the marquee.
    You can pass one or two functions to the trackMarquee method; both will be called with four arguments: the x1,y1,x2,y2 bounds of the marquee. The first function will be called when the marquee is released. The second function (if present) will be called each time the marquee moves (so that you can, for example, calculate what items are within that bounding box).

    When you start dragging on the SVG document (or whatever element you choose to track) it will create a <rect class="marquee" />; during dragging it will adjust the size of the rectangle. Use CSS (as seen in the demo) to style this rectangle however you want. I’m using the stroke-dasharray property to make the border dotted.

    For Stack Overflow posterity, here’s the code (on the off chance that JSFiddle is down):

    (function createMarquee(global){
      var svgNS = 'http://www.w3.org/2000/svg',
          svg   = document.createElementNS(svgNS,'svg'),
          pt    = svg.createSVGPoint();
    
      // Usage: trackMarquee( mySVG, function(x1,y1,x2,y2){}, function(x1,y1,x2,y2){} );
      // The first function (if present) will be called when the marquee is released
      // The second function (if present) will be called as the marquee is changed
      // Use the CSS selector `rect.marquee` to select the marquee for visual styling
      global.trackMarquee = function(forElement,onRelease,onDrag){
        forElement.addEventListener('mousedown',function(evt){
          var point0 = getLocalCoordinatesFromMouseEvent(forElement,evt);
          var marquee = document.createElementNS(svgNS,'rect');
          marquee.setAttribute('class','marquee');
          updateMarquee(marquee,point0,point0);
          forElement.appendChild(marquee);
          document.documentElement.addEventListener('mousemove',trackMouseMove,false);
          document.documentElement.addEventListener('mouseup',stopTrackingMove,false);
          function trackMouseMove(evt){
            var point1 = getLocalCoordinatesFromMouseEvent(forElement,evt);
            updateMarquee(marquee,point0,point1);
            if (onDrag) callWithBBox(onDrag,marquee);
          }
          function stopTrackingMove(){
            document.documentElement.removeEventListener('mousemove',trackMouseMove,false);
            document.documentElement.removeEventListener('mouseup',stopTrackingMove,false);
            forElement.removeChild(marquee);
            if (onRelease) callWithBBox(onRelease,marquee);
          }
        },false);
      };
    
      function callWithBBox(func,rect){
        var x = rect.getAttribute('x')*1,
            y = rect.getAttribute('y')*1,
            w = rect.getAttribute('width')*1,
            h = rect.getAttribute('height')*1;
        func(x,y,x+w,y+h);
      }
    
      function updateMarquee(rect,p0,p1){
        var xs = [p0.x,p1.x].sort(sortByNumber),
            ys = [p0.y,p1.y].sort(sortByNumber);
        rect.setAttribute('x',xs[0]);
        rect.setAttribute('y',ys[0]);
        rect.setAttribute('width', xs[1]-xs[0]);
        rect.setAttribute('height',ys[1]-ys[0]);
      }
    
      function getLocalCoordinatesFromMouseEvent(el,evt){
        pt.x = evt.clientX; pt.y = evt.clientY;
        return pt.matrixTransform(el.getScreenCTM().inverse());
      }
    
      function sortByNumber(a,b){ return a-b }
    })(window);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm not sure exactly what kind of design i'm looking for but basically we
I'm not sure what exactly to call this, but I've been able to reproduce
I'm not sure exactly where this is happening, but what I'm trying to do
I am fairly new to MVC but not sure exactly which Redirect... replaces the
I'm trying to debug this problem but not sure where exactly i need to
I've looked for an answer to this, but not finding exactly what I'm looking
I have seen a few examples of this but am not sure exactly how
Sorry if the question title is a little confusing, but I'm not sure exactly
Not sure exactly what I need to do to make this work, so my
I'm not sure exactly how to describe what I want to do, so I'll

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.