简体   繁体   English

链接JS过渡图像

[英]Link a JS rollover image

I have been trying to create a simple rollover image, and I have done so with CSS and JavaScript methods. 我一直在尝试创建一个简单的过渡图像,并且已经使用CSS和JavaScript方法进行了创建。 However, I cannot get this image to link. 但是,我无法链接此图像。

In the CSS version (as viewed below), I was using background images, and the link was not recognized in the "empty" HTML block. 在CSS版本中(如下图所示),我使用的是背景图片,并且在“空” HTML块中未识别出该链接。

In the JS version, the images are being called from the images folder. 在JS版本中,图像是从images文件夹中调用的。 Like the CSS, the link is not recognized in the "empty" HTML block. 与CSS一样,该链接在“ empty” HTML块中无法识别。 The moment I put an image in the HTML block, my rollover stops working. 在将图像放入HTML块中的那一刻,翻转就停止了。

I currently have the following in my HTML code. 目前,我的HTML代码中包含以下内容。 The rollovers work, but the link does not: 过渡有效,但是链接不起作用:

<div class="quick-map"><a href="Services/FloorPlan.aspx" onclick="window.open(this.href);return false;">&nbsp;</a></div>

In this example, the link works, but the rollovers do not: 在此示例中,链接有效,但过渡无效:

<div class="quick-map"><a href="Services/FloorPlan.aspx" onmouseover="document.MyImage.src='images/quick-map.png';" onmouseout="document.MyImage.src='images/quick-map-over.png';"><img alt="" src="images/quick-map.png" /></a></div>

Any suggestions would be greatly appreciated. 任何建议将不胜感激。 This has got to be something so simple, and I just don't understand why it's not working. 这一定很简单,我只是不明白为什么它不起作用。 I could have sworn I was doing this correctly... 我可能发誓我做得正确...

Try to use this: 尝试使用此:

<div class="quick-map">
 <a href="Services/FloorPlan.aspx" onmouseover="document.getElementById('MyImage').src='images/quick-map.png';" onmouseout="document.getElementById('MyImage').src='images/quick-map-over.png';">
  <img alt="" src="images/quick-map.png" id="MyImage" />
 </a>
</div>

Remember that id needs to be unique per page, so if you have multiple images they need different ids 请记住,每个页面的id必须是唯一的,因此,如果您有多张图片,则它们需要不同的ID

I just figured it out. 我只是想通了。 Turns out that I have to also give a display: block with width and height to the <span> tag in addition to the images I am referencing in my CSS. 事实证明,除了我在CSS中引用的图像之外,我还必须显示: <span>标签具有宽度和高度的 I knew it was something simple...thank you all for your help. 我知道这很简单...谢谢大家的帮助。

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

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