tags:

views:

147

answers:

3

Here is the site I'm currently working on: http://willcrichton.net/

If you click on the arrows on each side of the hexagon in the middle, you can see that it transitions left and right using jQuery + jQuery Cycle + jQuery Easing. However, you can also see that it is rather ugly -- because I'm using hexagons and not squares and because divs are square shaped, the content hexagon overlaps with with the background in an unpleasant way.

So, my question is: how would I essentially hack a div into a hexagon? That hexagon should be the same size/shape of the content div, and when content is outside the area of the hexagon it should be invisible.

Edit:

HTML

<div id="content"> 
<div class="slide">

    <a href="#"><div class="arrow left"></div></a>
    <a href="#"><div class="arrow right"></div></a>

    <div id="websites-title"></div>
    <div class="website">

    </div>
</div>
<div class="slide">
    <a href="#"><div class="arrow left"></div></a>
    <a href="#"><div class="arrow right"></div></a>

</div></div>


<script type="text/javascript">
    $("#content").cycle({
        fx: 'scrollHorz',
        timeout: 0,
        prev: ".left",
        next: ".right",
        easing: "easeInOutBack"
    });
</script>

CSS

/* Container styles */

#container {
    width: 908px;
    height: 787px;
    left: 50%;
    top: 50%;
    position: absolute;
    margin-top: -393.5px;
    margin-left: -452px;
    background-image: url("images/background.png");
    font: 12px "Lucida Sans Unicode", "Arial", sans-serif;
    z-index: 3;
}    

#content {
    width: 686px;
    height: 598px;
    position: absolute;
    left: 50%;
    top: 50%;
    margin-top: -282px;
    margin-left: -343.5px;
    /*background-image: url("images/hacky_hole2.png");*/
    z-index: 1;
}

    .slide {
        width: 100%;
        height: 100%;
        background-image: url("images/content.png");
        position: relative;
        z-index: 2;
    }

UPDATE: If you check the site now, you'd see my failed attempt at using the "window" method and you can see why the z-index did not work.

+2  A: 

You can't make a div into a hexagon, but you could use PNG files with alpha transparencies to mask the area you want. So, you would need to make four divs, each with a background that has a PNG file with the transparency that acts as a mask. These divs would be positioned absolutely over your div with the slider.

EDIT: As Pekka noted below, this could also be done with a single, large PNG file acting as a mask.

EDIT #2: Looking at the code you posted, I would revise it like this:

<div id="content"></div>
<div class="slide">

    <a href="#"><div class="arrow left"></div></a>
    <a href="#"><div class="arrow right"></div></a>

    <div id="websites-title"></div>
    <div class="website">

    </div>
</div>
<div class="slide">
    <a href="#"><div class="arrow left"></div></a>
    <a href="#"><div class="arrow right"></div></a>
</div>

Note that I closed the <div id="content"> element. This element should be a sibling of your slides, but be positioned above the slides with a higher z-index. Or, you may need to create a new element dedicated to displaying the mask, if your "content" div is used for other purposes than just displaying the mask.

Jeff Fohl
I have tried a similar solution, but for some reason when I use z-index to position the window above the content it doesn't work. Any idea why/any alternatives?
Will
The problem is that those PNGs would have a visible area that is the mask. You would effectively have to put the whole hexagon that is visible now into the PNG, and leave a hole in the middle. This will work but it's not very flexible (not that I'd have a better idea...)
Pekka
Make sure that the elements are positioned absolutely, with `position:absolute`. You will also meed to make sure that the parent element has the attribute `position:relative`, so the elements are all positioned relative to the same parent. Then, of course, make sure that your z-indexes stacks your elements in the order you want. If you post some code, I could take a look at it.
Jeff Fohl
@Pekka - Yes, that would be one option. You could also just use the part of the hexagon that you want to block the slider below. So, it would be one facet of the hexagon.
Jeff Fohl
@Jeff mmm, look at the white space outside the hexagon. You'd have to mask that as well, otherwise the sliding content will be visible there... I can't really think of a way to do this except to have the full hexagon's area in one image. Of course, I can be wrong.
Pekka
@Pekka - Yes, you are correct. The mask would have to have the white background as well. The method could use one div with one large background, or four divs, each covering one facet of the hexagon. They would both work. In both cases, the white background would have to be included.
Jeff Fohl
By the way - this method won't work in IE6. Not sure if you care about that or not.
Jeff Fohl
That was strange, the closing div tag didn't show in the syntax highlighter. Oh well, but it was closed -- it's not a concurrent div, it's a parent div for all the hexagons and whatnot.
Will
@Will - in that case, you will need to create a new div element that is a sibling of the slider divs, but positioned above them. This div will contain your mask.
Jeff Fohl
@Jeff: New problem. I tried that and it ALMOST works, but the problem is the mask disables the ability to click the links. If you check it again, you can see the content fine, but because the mask is above it you can't click on the links inside it.
Will
OK - your links will also have to positioned absolutely, above everything else. Basically, you will have to position everything in your layout absolutely (except the outermost container) and stack everything in the order you want.
Jeff Fohl
Ah - I think I see what you are saying - the links INSIDE the slides need to be clickable, right? OK, here is another approach. Instead of using a single large div with a background as a mask (this is what is blocking your clicks) create four masks (one for each corner) and position the image itself absolutely above the slides. This will leave the center area clickable. You still won't be able to click on areas covered by the transparency of your mask images however, so only the very center will be clickable. Follow?
Jeff Fohl
I think I understand what you're getting at, but that still poses a problem in that since the corners are diagonal then the div would still have to be triangular in order to create the proper window I'm looking for.And thanks for your help by the way, you're the first person to be able to provide any help at all.
Will
Well, yes - you won't be able to make the transparent areas clickable, but at least you will be able to have some of the area be clickable, so if you design your slides properly, it might work.
Jeff Fohl
One last thing you could do is to use CSS Transforms to create masks that are much more slim, and rotate them into place. However CSS transforms are only supported in Firefox and Webkit (not Internet Explorer). Here is a blog post about it: http://davidwalsh.name/css-transform-rotate
Jeff Fohl
A: 

If it was me developing, I would make that two layer link of yours, into a tree layer...

ex:

1. Layer with the existing background

2. Layer with the gray hexagon

3. Layer with the surrounding words and the surrounding background

Like that, when you click the left and right arrows, the gray hexagon will me sliding in the middle of the 1. and 3. layers, thus preventing that ugliness that you've mentioned :)

Hope it helps!

Zuul
+1  A: 

Eric Meyer's curvelicious concept and demo might point you in the right direction. It's a complicated hack from the "early days of CSS", but it's a powerful technique.

kevingessner