繁体   English   中英

将鼠标悬停在文本上,然后更改图像在以下IE8中不起作用

[英]Mouseover text then Change Image not Working in IE8-below

我有一个用JavaScript制作的横幅,当您将鼠标悬停在特定文本上时,横幅中的图像会发生变化。

我想知道如何使其在ie8中兼容。

我使用了本教程来提出js:

http://www.javascriptkit.com/script/script2/rolldifferent.shtml

我也尝试将鼠标移出,然后图像会改变。

这是js代码:

<script type="text/javascript">function changeimage(towhat,url){if (document.images){document.images.targetimage.src=towhat.src gotolink=url}}functionwarp({window.location=gotolink}</script>

<script>var myimages=new Array()var gotolink="#"function preloadimages(){for (i=0;i<preloadimages.arguments.length;i++){myimages[i]=newImage()myimages[i].src=preloadimages.arguments[i]}}preloadimages("map_wm_hover.gif", "map_wm_hover2.gif","map_wm.gif")</script>

这是CSS:

<div id="base"><div id="mapcontainer"><a href="javascript:warp()"><img src="map_wm.gif" name="targetimage" border=0></a></div>


<div id="textcontainer"><div class="textboxinner1"><a href="index.html"onMouseover="changeimage(myimages[2],this.href)">8CCC REQUESTS/TALKBACK</a></div>

<div class="textboxinner2"><a href="index.html"onMouseover="changeimage(myimages[1],this.href)">Alice Springs  8952 7771</a></div>

<div class="textboxinner2"><a href="index.html"onMouseover="changeimage(myimages[0],this.href)">Tenant Creek 8952 7182</a></div>

<div class="textboxinner3"><span class="t3nonelink">...other contact details <a href="index.html" onMouseover="changeimage(myimages[2],this.href)">here</a></span></div>

我认为这是IE的问题,其中gif动画无法正确加载到javascript中。 一种解决方法是将图像放在HTML代码的隐藏div中,而不是将其加载到脚本中。 积极的副作用是,这大大简化了javascript。 参见http://jsfiddle.net/5pZLT/7

HTML:

<DIV id=base>
    <DIV id=mapcontainer><A href="javascript:warp()"><IMG border=0 name=targetimage src ="http://www.keencloudmedia.com/skybluekangaroo/map_wm.gif"></A> </DIV>
<DIV id=textcontainer>
<DIV class=textboxinner1><A onmouseover=changeimage(2,this.href) 
href="index.html">8CCC REQUESTS/TALKBACK</A> </DIV>
<DIV class=textboxinner2><A onmouseover=changeimage(1,this.href) 
href="index.html">Alice Springs 8952 7771</A> </DIV>
<DIV class=textboxinner2><A onmouseover=changeimage(0,this.href) 
href="index.html">Tenant Creek 8952 7182</A> </DIV>
<DIV class=textboxinner3><SPAN class=t3nonelink>...other contact details <A 
onmouseover=changeimage(2,this.href) href="index.html">here</A></SPAN> 
    </DIV></DIV></DIV><div id="hiddenImages" style="display: none">
<img src="http://www.keencloudmedia.com/skybluekangaroo/map_wm_hover.gif" name="hoverImage" />
<img src="http://www.keencloudmedia.com/skybluekangaroo/map_wm_hover2.gif" name="hoverImage2" />
<img src="http://www.keencloudmedia.com/skybluekangaroo/map_wm.gif" name="originalImage" />
</div>​

Javascript:

var gotolink = "#";
function changeimage(imageNumber, url) {
    if (document.images) {
        document.images.targetimage.src = 
            document.getElementById('hiddenImages').children[imageNumber].src;
        gotolink = url;
    }
}

顺便说一句,您的原始代码中缺少很多;,这往往会使它停止工作。

暂无
暂无

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

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