Polygonal Divs——让内容以特定形状溢出?
这是我当前正在处理的网站: http://willcrichton.net/
如果您单击箭头在中间六边形的每一侧,您可以看到它使用 jQuery + jQuery Cycle + jQuery Easing 左右过渡。然而,您也可以看到它相当难看——因为我使用的是六边形而不是正方形,而且因为 div 是方形的,所以内容六边形与背景以一种令人不愉快的方式重叠。
所以,我的问题是:我如何将 div 破解成六边形?该六边形应该与内容 div 的大小/形状相同,并且当内容位于六边形区域之外时,它应该是不可见的。
编辑:
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; }
更新:如果您现在检查该网站,您会看到我使用“窗口”方法的失败尝试,并且您可以看到为什么 z-index 不起作用。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您无法将 div 制作成六边形,但您可以使用带有 alpha 透明度的 PNG 文件来遮盖您想要的区域。因此,您需要制作四个 div,每个 div 都有一个背景,其中包含一个具有充当遮罩透明度的 PNG 文件。这些 div 将通过滑块绝对定位在您的 div 上。
编辑:正如 Pekka 下面指出的,这也可以通过一个大的 PNG 文件作为遮罩来完成。
编辑#2:查看您发布的代码,我将对其进行如下修改:
请注意,我关闭了
元素。该元素应该是幻灯片的同级元素,但位于具有较高 z-index 的幻灯片上方。或者,如果您的“内容”div 用于其他目的而不仅仅是显示蒙版,则您可能需要创建一个专用于显示蒙版的新元素。
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:
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.如果是我开发,我会把你的两层链接变成树层......
例如:
就像这样,当您单击左右箭头,灰色六边形将使我在第 1 层和第 3 层中间滑动,从而防止您提到的丑陋:)
希望它有帮助!
If it was me developing, I would make that two layer link of yours, into a tree layer...
ex:
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!
Eric Meyer 的 curvelicious 概念和演示可能会为您指明正确的方向。这是“CSS 早期”的复杂技巧,但它是一项强大的技术。
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.