【问题标题】:show-hide image onmouseover鼠标悬停时显示隐藏图像
【发布时间】:2011-02-09 06:06:26
【问题描述】:

我有 3 张图像重叠在一起。第一个是普通的 .jpg 图像,第二个是灰度版本,第三个是我用透明的 .png 添加的某种效果

现在我想要的是,如果我将鼠标移到这些图像上,灰度图像会被隐藏或被另一个图像替换,然后再次可见。

这里的问题是我是一个js菜鸟,所以我很难找到解决方案^^

我的代码如下所示:

<html> 
<head>
<style type="text/css">
<!--                                               
ul li{                     
  display: inline-table;
}
.frame{
  position: relative;  
  height: 110px;
  width: 110px;
}  
.frame div{
  position: absolute;
  top:0px;
  left:0px;              
}       
.effect{                                           
  background:url(images/effect.png) no-repeat;
  height:110px;
  width: 110px; 
}  
.image{
  height:100px;
  width:100px;
  border: 1px solid red;
  margin:4px;    
}
.greyscale{ 
  height:100px;
  width:100px;
  border: 1px solid red;
  margin:4px;          
}    
-->
</style>
</head>

<body>
<ul>
  <li>
    <div class="frame">
      <div class="image"><img src="images/pic1.jpg" height="100" width="100"></div>      
      <div class="greyscale"><img src="images/grey1.jpg" height="100" width="100"></div>
      <div class="effect">qwert</div>
    </div>
  </li> 
  <li>
    <div class="frame">
      <div class="image"><img src="images/pic2.jpg" height="100" width="100"></div>
      <div class="greyscale"><img src="images/grey2.jpg" height="100" width="100"></div>
      <div class="effect">qewrt</div>
    </div>
  </li> 
</ul>

</body>
</html>

如果有人可以帮助我,那就太棒了:)

【问题讨论】:

标签: javascript html image onmouseover


【解决方案1】:

尝试将此添加到您的 css 中:

div.greyscale:hover img { display: none; }

如果您将鼠标悬停在灰度 div 上,这将隐藏您的图像。

【讨论】:

    【解决方案2】:

    试试这个:

    .frame:hover .greyscale { display: none; }
    

    【讨论】:

      【解决方案3】:

      看看这个例子,

      我在上面有一张大图,下面有 3 张图片。

      在鼠标悬停 sll 3 图像时,它们将替换大的图像。鼠标移出旧图像会回来

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      <title>Untitled Document</title><br />
      
      </head>
      
      <body>
      <p>
        <script type="text/javascript" language="javascript">
      function changeImage(img){
         document.getElementById('bigImage').src=img;
      
      }
      </script>
      
        <img src="../Pictures/Bigcircle.png" alt="" width="284" height="156" id="bigImage" />
      <p>&nbsp; </p>
      <div>
        <p>
        <img src="../Pictures/lightcircle1.png" height=79 width=78 onmouseover="changeImage('../Pictures/lightcircle2.png')" onmouseout="changeImage('../Pictures/Bigcircle.png')"/>
      
       </p>
       <p><img src="../Pictures/lightcircle2.png" alt="" width="120" height="100" onmouseover="changeImage('../Pictures/lightcircle.png')" onmouseout="changeImage('../Pictures/Bigcircle.png')"/></p>
      
       <p><img src="../Pictures/lightcircle3.png" alt="" width="78" height="79" onmouseover="changeImage('../Pictures/lightcircle2.png')" onmouseout="changeImage('../Pictures/Bigcircle.png')"/></p>
      
       <p>&nbsp;</p>
      
      
        </br>
      </div>
      </body>
      </html>
      

      您可以根据需要对其进行修改。 干杯..

      【讨论】:

        猜你喜欢
        • 2012-01-27
        • 2017-04-10
        • 1970-01-01
        • 1970-01-01
        • 2019-04-21
        • 2013-07-08
        • 1970-01-01
        • 2013-02-18
        • 2016-04-26
        相关资源
        最近更新 更多