简体   繁体   English

映射元素的背景图像

[英]Mapping background-image of element

I know we have <map> and <area> for mapping an image. 我知道我们有<map><area>用于映射图像。 I want to use polygon mode of this. 我想使用这种多边形模式。

But just imagine I have a div element with a background-image and I want to map the background image like <img> . 但是,试想一下,我有一个带有背景图像的div元素,并且想要映射<img>这样的背景图像。

My shape isn't rectangle or square; 我的形状不是矩形或正方形; it's a polygon. 这是一个多边形。 And I don't want to use transparent div trick. 而且我不想使用透明的div技巧。

How can I map this? 我该如何映射?

Use a transparent image (eg with opacity:0 ) with an imagemaps, positioned over your div. 将透明图像(例如opacity:0 )与图像映射一起使用,并将其放置在div上。 This effect is how the ImageMapster plugin works. 此效果就是ImageMapster插件的工作方式。

I wrote a blog post that explains how these effects work. 我写了一篇博客文章 ,解释了这些效果的工作原理。 The long and short of it is, you can use HTML image maps on top of anything you want. 总而言之,您可以在所需的任何内容之上使用HTML图像映射。 All you need to do is to ensure that the img has the highest z-index , and is transparent, and is positioned absolutely on top of the element you want your end-user to actually see. 您需要做的就是确保img具有最高的z-index ,并且是透明的,并且绝对位于要最终用户实际看到的元素的顶部。 If it's transparent, the end-user will only see what's behind it, giving you total flexibility to use the polygon position tracking capabilities of imagemaps on to of any other kind of elementsuch as a div . 如果它是透明的,则最终用户将只看到其背后的内容,从而使您可以完全灵活地将imagemaps的多边形位置跟踪功能应用于任何其他类型的元素,例如div

Example: 例:

<div id="container">
    <img style="position: absolute; top: 0; left: 0; opacity: 0; 
                width: 100px; height: 100px;" 
         src="/placeholder.jpg" 
         usemap="#my-image-map">
    <div style="position: absolute; top: 0; left:0; 
                background-image: url(/some-100-by-100-pixel-image.jpg)">
</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM