简体   繁体   English

对图像多个区域的翻转效果

[英]Rollover Effect on Multiple Areas of an Image

I'm trying to make a rollover effect on specific parts of an image. 我正在尝试对图像的特定部分进行翻转效果。 So depending on which area is hovered over the image would change to a different image. 因此,根据将鼠标悬停在哪个区域上,图像将更改为其他图像。 I also want those parts of the image to be clickable. 我也希望图像的那些部分是可单击的。 I don't think I can simply map the area I want to do the rollovers and links because I want the images/clickable areas to size dynamically according to the size of the browser. 我认为我不能简单地映射要进行翻转和链接的区域,因为我希望图像/可单击区域根据浏览器的大小动态调整大小。

This is what I have so far: 这是我到目前为止的内容:

The image is under this CSS: 该图像在此CSS下:

#banner {
    width: 100%;
    margin-top: 0px;
    margin-bottom: auto;
    margin-left: 0px;
    margin-right: auto;
    position: relative
 }

And I made a clickable box in CSS: 我在CSS中创建了一个可点击的框:

a.box1{
    display: block;
    position: absolute;
    top: 17%;
    left: 16%;
    width: 15.5%;
    height: 9%;
}

Do you guys have any Javascript tips on how to do this. 你们有关于如何执行此操作的任何Javascript技巧吗? I'm thinking about doing something like this http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_onmouseover , but I would need to specify an image. 我正在考虑做这样的事情http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_onmouseover ,但是我需要指定一个图像。 Is there a way to create a dynamically sized empty image box, like box1 (CSS above), since the rollover effect only goes off when you hover over a certain spot of the image. 有没有一种方法可以创建动态尺寸的空白图像框,如box1(上面的CSS),因为只有将鼠标悬停在图像的某个位置时,翻转效果才会消失。

You can do this fairly simply with image sprites, the same idea used in original video games. 您可以使用图像精灵来相当简单地完成此操作,这与原始视频游戏中使用的想法相同。 The best part is, you only have to use one image, which means the page will load beautifully and nothing other than some mathematical css is required - no javascript. 最好的部分是,您只需要使用一张图像,这意味着页面将漂亮地加载,除了一些数学CSS之外就不需要其他任何内容-无需JavaScript。 It works in every browser old and new. 它适用于所有新旧浏览器。 This article from A List Apart explains the whole process: http://alistapart.com/article/sprites A List Apart的这篇文章介绍了整个过程: http : //alistapart.com/article/sprites

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

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