views:

39

answers:

2

Hi,

So I have a grid of images (map tiles) and I draw a semi-transparent mask over it using an absolutely positioned div with width and height set to 100%.

I now want the user to be able to draw out a rectangle on the mask, with the mouse using mouse-down, drag, mouse-up. The rectangle would be drawn dynamically as the mouse moves, and the rectangle would be like a window through the mask displaying the map tiles underneath with no semi-transparency.

I'm currently looking at using 5 divs - one for the window and 4 for the mask which would be resized using javascript as I drag the mouse. Does anyone know an easier way to do this ? I'm using jquery and I need to support IE7 upwards so html5 only technology is out.

Cheers,

Colm

A: 

You should try out SVG canvas instead. There's a SVG js library, good for beginner: http://raphaeljs.com/, check it out

PLEASE NOTE THAT THIS HAS NOTHING TO DO WITH HTML5 (PLEASE DONT MIX UP WITH HTML5 CANVAS, THIS IS SVG)

Yman
+1 for the good suggestion, but note that SVG and Canvas are not the same thing.
Spudley
These are HTML5 technology and it is quite difficult to get this to work fast with IE. Quote: _"I'm using jquery and I need to support IE7 upwards so html5 only technology is out."_
elusive
I'd love to use SVG but unfortunately as mentioned by elusive, having to support IE knocks that idea out .......
Protos
seriously, try it before u knock out this suggestion, and it DOES SUPPORT IE (even IE6) cos im using it.... it has nothing to do with HTML5
Yman
IE6 does not support SVG. You are probably using a library that uses VML in IE browsers and SVG in other browsers that support it.
Protos
@Yman: There is nothing like SVG in IE. IE only has VML, which is a proprietary Microsoft thing. Like i said, it is very difficult to get this to run at acceptable speed. The same thing applies to _HTML5_ `<canvas>`, even though you removed it from your post.
elusive
what do you mean "even though you removed it from your post"?
Yman
btw, u are right, it is VML, though it still answer the question
Yman
+1  A: 

I think the jQuery Crop plugin does exactly what you need (Demo here).

Maybe it's possible to carve that part out from it.

Pekka
This looks very interesting - thanks ! will check it out.
Protos