三角形图像映射和悬停效果

发布于 2024-11-10 03:04:37 字数 339 浏览 1 评论 0原文

我正在尝试用我拥有的两个三角形创建一个非常简单的悬停效果。其中一个三角形将从其下方开始,然后悬停时显示在另一个三角形上方。

问题并不是真正的效果,而是区域框妨碍了。这意味着左侧三角形(其 z 索引暂时位于另一个三角形之上)不必要地重叠,因为它的周长是正方形并且有大量浪费的空间。

因此,将鼠标悬停在三角形 2 上仅适用于有限的区域。我尝试制作图像图并利用坐标图来完成我需要的操作,但我不知道如何在使用它来完成我需要做的事情时将其保持为三角形格式。它只是去一个广场。

有办法做到这一点吗?它基本上只是悬停在特定形状上,但 CSS/HTML 似乎仅限于正方形。任何 jQuery 解决方案或..?

谢谢。

I'm trying to create a pretty simple hover effect with two triangles that I have. One of the triangle would start off underneath it, then on hover, show above the other triangle.

The issue isn't really the effect, it's that the area boxes get in the way. Meaning the left triangle, which temporarily has a z-index above the other triangle, overlaps unnecessarily just because it's perimeter is a square and has a lot of wasted space.

So hovering over triangle 2 only works in so many areas. I've tried to do an image map and utilizing the coordinate maps to do what I need, but I couldn't figure out how to keep it in triangle format while using it to do what I need to do. It just goes to a square.

Is there a way to do this? It's basically just hovering over a specific shape, but CSS/HTML seems to be limited to squares. Any jQuery solutions or..?

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小矜持 2024-11-17 03:04:37

在 100% 不知道你要做什么的情况下,我将建议一种通用方法,用于克服我在过去的项目中遇到的有点类似的问题。

最简单的方法是将所有图像放置在同一个暂存容器中,例如带有 position:relative 的 div,用于为图像提供堆叠和定位上下文。最后,用透明的 1x1 GIF 或 PNG 图像覆盖整个 div,该图像作为宽度/高度为 100% 的标记中的最后一个子级放置,并将图像映射应用到该空白图像。创建三角形所需的区域类型是“多边形”区域。这允许您指定自由形式的点对点图像地图区域。然后,您可以将鼠标悬停/鼠标悬停 JavaScript 链接到该图像映射区域。

例如(CSS 定位和地图坐标只是一个示例,当然,您必须自己指定它们):

HTML

<div class="imagePanel">
    <img src="http://www.mysite.com/images/triangle1.png" alt="" class="triangle1" />
    <img src="http://www.mysite.com/images/triangle2.png" alt="" class="triangle2" />
    <img src="http://www.mysite.com/images/blank.gif" alt="" class="imageMap" usemap="#mapOver"/>
    <map id="mapOver" name="mapOver">
        <area id="areaTriangle" shape="poly" coords="25,240,108,100,190,240" href="#" />
    </map>
</div>

CSS

div.imagePanel
{
    position: relative;
    width: 300px;
    height: 300px;
}

div.imagePanel > img
{
    position: absolute;
}

img.triangle1
{
    left: 25px;
    top: 100px;
}

img.triangle2
{
    left: 75px;
    top: 75px;
    display: none;
}

img.imageMap
{
    top: 0px;
    left: 0px;
    width: 100%;
    height: 100%;
}

jQuery< /strong>

$(function() {
    $("#areaTriangle").hover(function() {
        $("img.triangle2").show();
    }, function() {
        $("img.triangle2").hide();
    });
});

查看工作示例在此小提琴

Without 100% knowing what you're going for here, I'm going to suggest a general method I used to overcome a somewhat similar problem I had on a past project.

The easiest way to do this is to place all your images in the same staging container, such as a div with position: relative, that is used to give the images a stacking and positioning context. Finally, overlay the entire div with a transparent 1x1 GIF or PNG image that is placed as the last child in the markup with 100% width/height and apply an image map to that blank image. The type of area necessary for creating the triangle shape is a "poly" area. This allows you to specify free-form point-to-point image map area. You would then link your mouseover/mouseout JavaScript to this image map area.

For instance (the CSS positioning and map coordinates are just an example and you will have to specify those yourself, of course):

The HTML

<div class="imagePanel">
    <img src="http://www.mysite.com/images/triangle1.png" alt="" class="triangle1" />
    <img src="http://www.mysite.com/images/triangle2.png" alt="" class="triangle2" />
    <img src="http://www.mysite.com/images/blank.gif" alt="" class="imageMap" usemap="#mapOver"/>
    <map id="mapOver" name="mapOver">
        <area id="areaTriangle" shape="poly" coords="25,240,108,100,190,240" href="#" />
    </map>
</div>

The CSS

div.imagePanel
{
    position: relative;
    width: 300px;
    height: 300px;
}

div.imagePanel > img
{
    position: absolute;
}

img.triangle1
{
    left: 25px;
    top: 100px;
}

img.triangle2
{
    left: 75px;
    top: 75px;
    display: none;
}

img.imageMap
{
    top: 0px;
    left: 0px;
    width: 100%;
    height: 100%;
}

The jQuery

$(function() {
    $("#areaTriangle").hover(function() {
        $("img.triangle2").show();
    }, function() {
        $("img.triangle2").hide();
    });
});

See a working example at this fiddle.

最舍不得你 2024-11-17 03:04:37

ImageMapster,我的 jquery 图像地图插件 可能会让您使用图像地图轻松地完成此操作。从描述中尚不完全清楚您要做什么,但该插件允许您使用第二张图像来实现突出显示效果,并且还允许您定义事件后要显示的悬停区域以外的区域。

此示例可能与您想要实现的目标类似(将鼠标悬停在中间圆圈)。您可以让矩形(==您的第二个三角形)在鼠标悬停之前不可见。

ImageMapster, my jquery image map plugin will probably enable you to do this pretty easily with an image map. It's not totally clear what you are trying to do from the description but the plugin lets you use a second image for a highlight effect, and also lets you define areas other than the hover area to be shown after an event.

This example may be similar to what you are trying to achieve (mouse over the middle circle). You could just have the rectangle (== your 2nd triangle) be invisible before a mouseover.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文