Mutually clickable overlayed elements - javascript

Okay, so I'm finding a lot of answers that don't quite fit my need. Here is my scenario: I have an app in javascript/html/css. I have two independently rotatable overlayed elements (in this case both svg's) that both have elements that need to be clickable which move around their perimers with the rotation of the two elements. One layer has 7 clickable points, the other has 12 clickable points, and the two rotate to a given point based on onclick events that set a target degree for the rotation. Only the points (i.e. small transparent circles at the edge of a circular radius on each of the two svg's) need to be clickable. My problem is that whichever layer I put on top works, but the buttons on the other layer then stop working, apparently blocked by the other's background. I've tried messing with all sorts of pointer events and some other ideas on StackOverflow, but all end with the same result: one set of buttons doesn't work. They need to be on separate layers so the rotation will put them at the correct position as they rotate in real-time. Any ideas would be welcome. I am looking for an answer that requires no libraries (including jquery), however if it can be done with jquery, then it can be done without jquery-- if I can find out how. Ideas anyone?

#dandavis is pretty much right here, except I think he meant to say pointer-events: auto . Was just noting there's not an official 'answer' posted. For now, marking this one, but if you want to re-post as an 'answer', Dan, I will gladly mark it as the accepted one.

Related

Having multiple canvas layers javascript

I am trying to do a paint app. But that's not all. I want to extend it with possibility of layers like in gimp or photoshop. Some of layers can be visible and others not. It all depends of user needs.
I tried a lot. There are some of my ideas how to do it:
First i tried to add new canvases to html document and changing z-index of elements. The problem of this was that addEventListener didn't know what i did. I mean that it didn't know on which layer i am actually pressing.
Second idea was to take of all points (vertices) of line, put it in array and then redraw it. It all will happen in area of one canvas element.
The last one and i think the best idea was to have multiple 2d contexts. But i don't know how to make it invisible. I saw only ctx.globalAlpha property but it needs to be configured before drawing.
Maybe someone knows what is actually the best method to achieve it. I will be very thankful for every response.

Can I use area maps as a divs and give them style? [duplicate]

I'm created a very large map with many poly areas (over 20 coordinates each) for regions within the map. However, you can't add css to the AREA tag as I was told it's not a visible element. What I want to do is when the user hovers over an area on the map, I want it to be "highlighted" by applying a 1px border to the specific AREA element. Is there a way of doing this? No, I'm not going to resort using rectangles.
Not possible with CSS.
You might check out the Map Hilight jQuery plugin, though.
EDIT 10.2011
ImageMapster is a more recent, and more powerful plugin you should also check out.
If you want to be able to use arbitrary shapes and still use styles, have you considered trying SVG?
I'm not an SVG master but here's an example I whipped up: http://jsfiddle.net/tZKuv/3/. For production you may want to replace the default stroke with none, I used gray so you can see where it is.
The disadvantage is that you'd lose the ease-of-use area/map gives you, but I imagine you can accomplish your goal if you go this route. I added cursor: pointer to the polygon and you can add onclick handlers to simulate the href of <area>.
An obvious caveat is browser support. This seems to be working in Chrome, and I am pretty sure it should work in IE9 (jsfiddle's not working in IE9 at the moment), but previous versions of IE don't support SVG.
Update: Made a quick test page to test IE9. It does indeed work as expected. Here's the source.
Update again: This would also solve the zooming problem you asked about in another question.
Nope, there is no way to do this as you describe. I've researched it and tried. What you can do is set up mouseover events on the various segments and swap some overlay image that is shaded in the same area.

Rendering elements around a central point

I've got a bit of a tricky question I couldn't find the answer to. Basically, This is what I have:
In the center is a search box (fixed to the center of the page), and around it are dynamically loaded search results of differing sizes (although, if need be these can be restricted). Thing is, they need to "wrap" around the search box after the results have been loaded. My normal go-to is floating, but this isn't really going to work, as the box isn't aligned to a particular direction.
I've looked at jQuery Masonry for a solution, but it isn't going to work for me (doesn't detect fixed elements, doesn't work from a point).
Any pointers in terms of solutions or Google-Fu would be much appreciated.
This is similar to packing textures of different sizes on a square. Have a look at this algorithm: http://www.blackpawn.com/texts/lightmaps/default.html
Since you have a central fixed box, maybe you can divide your available space in 4 rectangles and then pack the boxes into them.

looking for suggestions on how i can highlight areas on an image

i am building a workout website that tracks exercises. Each exercise has a mapping to a certain part of the body (bench press --> Chest)
I am trying to figure out a way to visualize this and i thought of the idea of putting an image of a person "highlighting" the affected muscles. Sort of like This:
(source: aquaviews.net)
Assuming i have found a good picture without any areas highlighted, is there anyway to dynamically "highlight" areas in a picture (the red section) with javascript (client side) or C# (server side) or do i need a seperate picture for every exercise?
You COULD overlay the the base image with SVG or a <canvas> element.
But then you have cross-browser issues, possible alignment problems, and probably a cheesy look.
I'd have an artistically inclined person do the highlights as a separate graphic for each exercise.
But rather than have these as separate images, keep/combine them in a single file -- as a CSS Sprite. Then you get a professional appearance, great cross-browser support and easy, minimal coding.
You can use css to position your links over said muscle group and use a rollover to show the highlighed part...
Edit:
Sorry I guess I should have elaborated. You can absolutely position the elements with CSS and use an image rollover to swap out that section of the image to the highlighted section of that image. You can either do this by putting each muscle group into it's own div and putting an image of the corresponding muscle group into the background image. Then swap it out on rollow over. or you can use z-index and absolutely position the rollover elements where they need to be and change the z-index when needed.
Interestingly enough, I used to be a personal trainer and I did this same thing but did it in flash. That's my recommendation.
However, if you want to do it with JS and CSS, Brock's suggestion of the sprites is likely the way to go.
What you could do, very simply, would be to have an image map that for certain areas called a js function to swap about the background image with the same version of that image with the highlighted sections. Rather than several small images, you have the same image but with one part highlighted.
One question though, will you be doing compound exercises that would require you to have two sections highlighted? For instance, an incline press would highlight part of the chest and part of the delts. This makes the whole proposition more complicated due to the specificity of your roll overs.
i think you seeking a way to do this without requiring separate images, and if so - the answer is No - you are going to need to create separate images for at least the highlighted areas. Short of perhaps using a CANVAS element which has cross-browser issues, I don't believe there is any way to impose a filter to an arbitrary region of an image element.
And even if you Could apply an alpha filter, you would still need the geometry of every shape, so the effort/work is perhaps the same...
Once you have the various images there are sundry ways to approach the problem after that...
This is a simple implementation as i have done this highlighting with a county map. Use an image map. Then find a highlighting script like (mapper.netzgesta.de) mapper.js. All you need to do is have a properly set up image map (image must be suuounded by a div) and a link to this script. The highlighting starts immediately. Please check the license. Ther are several other that scripts that use javascript css and jquery to achieve this same effect. Just research highlight image map in google. Sorry i cant give you a link to my implementation of this as it is on a secure site for work. Good Luck.

Javascript component for window/pane flip effect?

I'm prototyping a thin client UI using extjs and am looking for an effect that will simulate a form/pane flipping over to reveal another form/pane. Its for a details view for an object that has two major sets of properties.
I found a flex component that can do this, and can even simulate four different forms on the faces of a cube.
Just a sexier, more fun way of doing what you can already do with tabs.
This particular effect may not be available on a cross-browser basis quite yet. Doing perspective transforms on a given DOM element is only possible in two ways that I know of:
1) Renderer-specific extensions, like Webkit's -webkit-transform
2) Rendering the DOM element inside of a Canvas element and then doing transforms on that
The problem with #1 is that it's clearly not going to be cross-browser. The problem with #2 is that you'd more or less have to write your own complete markup renderer for canvas to really get everything in an arbitrary DOM element in there.
(OTOH, I wouldn't put it past some ambitious and clever JavaScript ninja to have attempted #2, so though I haven't seen it yet, I wouldn't be totally surprised if someone else can point towards something like it...)
I would stick with the tab solution if you want to get your project done within a reasonable time. This does not exist for ExtJS - the one in Flex does a 3D effect. The only solution close is to just have content in 4 cells of a table that slides into view (according to the direction of the arrow you used), within a DIV, and have the overflow property set to hide, so you can mask out the other cells and show one cell at a time. Then use the animation (fx) functions to slide the content in and out of view, perhaps with some arrows you hover over or click.

Categories

Resources