使用图像映射时,鼠标悬停上的图像闪烁javascript

image flicker javascript on mouseover when using image maps

本文关键字:图像 闪烁 悬停 javascript 映射 鼠标      更新时间:2023-09-26

我使用图像映射将一些图像悬停在滑块中,效果很好,但在加载一次之前会有闪烁,然后效果很好。有人知道为什么会发生这种事吗?

顺便说一下,它只发生在FIREFOX 中

<script>
    Image1 = new Image()
    Image1.src = "images/slide1aroll.jpg"
    function firstmap() {
        document.emp.src = Image1.src; 
        return true;
    }
</script>
<li style="width: 480px; height: 610px;"><img src="images/slide1a.jpg" name="emp" id="emp" class="emp" width="480" height="610" usemap="#model1" style="display:block; border:none;" border="0" /></li>
<map name="model1" id="model1" name="model1">
    <area shape="rect" coords="31,6,289,576" href="#" onmouseover="firstmap();" onmouseout="document.emp.src = 'images/slide1a.jpg';" alt=""/>
    <area shape="rect" coords="303,9,475,605" href="#" onmouseover="firstmap2();" onmouseout="document.emp.src = 'images/slide1a.jpg';" />
</map>

图像会闪烁,因为一旦切换图像,就会更改图像的来源。因此,现在您的鼠标悬停在另一个图像上,而不是您想要的图像。

一旦鼠标移到新加载的图像上,新图像就会被隐藏,因为您的鼠标现在没有悬停在旧图像上。当它被隐藏时,鼠标再次移到旧图像上,因此新图像再次可见。

该过程继续产生闪烁效果。旧图像-新图像-旧图像。。。。等等

希望这能有所帮助。

缓存图像

<div style="display: none">
    <img src="image1.png" />
    <img src="image2.png" />
    <img src="image3.png" />
</div>  

有了这个,你在第一次尝试时就有了所有的图像。它现在不会闪烁了。试试