完全css实现缩略图鼠标移上去显示大图

<!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=gb2312" />
<title>无标题文档</title>
<style type="text/css">
<!--
.list{position:relative;}
.list span img{ /*CSS for enlarged image*/
border-width: 0;
padding: 2px; width:500px;
}
.list span{ 
position: absolute;
padding: 3px;
border: 1px solid gray;
visibility: hidden;
background-color:#FFFFFF;
}
.list:hover{
background-color:transparent;
}
.list:hover span{
visibility: visible;
top:0; left:60px;
}
-->
</style>
</head>
<body>
<p> </p>
<div>
<a class="list" href="http://www.85flash.com/Get/wangyetuxiang/XinShang/2006-1-8/200124420.htm"><img src="http://www.85flash.com/Files/BeyondPic/2006-1/8/061819573345943.jpg" width="156" height="122" border="0" /><span><img src="http://www.85flash.com/Files/BeyondPic/2006-1/8/061819573345943.jpg" alt="big" /></span></a></div>
</body>
</html>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
您好!感谢您的提问。实现图片切换效果,可以使用JavaScript和CSS实现。具体实现步骤如下: 1. HTML结构 首先,需要在HTML中创建一个容器,用于显示图片缩略图。例如: ```html <div class="image-container"> <img src="image1.jpg" alt="Image 1" class="main-image"> <div class="thumbnails"> <img src="thumb1.jpg" alt="Thumbnail 1"> <img src="thumb2.jpg" alt="Thumbnail 2"> <img src="thumb3.jpg" alt="Thumbnail 3"> </div> </div> ``` 其中,`.main-image`类用于显示图片,`.thumbnails`类用于包含缩略图。 2. CSS样式 接下来,需要定义CSS样式,用于控制图片缩略图显示效果。例如: ```css .image-container { position: relative; } .main-image { width: 100%; height: auto; } .thumbnails { position: absolute; bottom: 0; left: 0; width: 100%; display: flex; justify-content: center; } .thumbnails img { width: 50px; height: auto; margin: 0 10px; cursor: pointer; border: 2px solid transparent; transition: border-color 0.3s ease-in-out; } .thumbnails img:hover { border-color: #ccc; } ``` 其中,`.image-container`类用于设置容器的位置,`.main-image`类用于设置主图片的宽度和高度,`.thumbnails`类用于设置缩略图容器的位置和宽度,并使用`flex`布局使缩略图水平居中显示。`.thumbnails img`类用于设置缩略图的宽度、高度、边距和光标样式,并使用`transition`属性设置动画效果。`.thumbnails img:hover`类用于设置鼠标悬停时的边框颜色。 3. JavaScript交互 最后,需要使用JavaScript实现缩略图的交互效果,即点击缩略图显示对应的大图片。例如: ```javascript const thumbnails = document.querySelectorAll('.thumbnails img'); const mainImage = document.querySelector('.main-image'); thumbnails.forEach(thumbnail => { thumbnail.addEventListener('click', () => { const imagePath = thumbnail.src.replace('thumb', 'image'); mainImage.src = imagePath; }); }); ``` 其中,`thumbnails`变量用于获取所有缩略图元素,`mainImage`变量用于获取主图片元素。然后,使用`forEach`方法循环遍历所有缩略图元素,为每个缩略图元素添加`click`事件监听器。当缩略图被点击时,获取缩略图的路径,并将`thumb`替换为`image`,即可得到对应的大图片路径。最后,将大图片路径赋值给主图片的`src`属性,即可实现缩略图切换效果。 希望这个回答能够帮助到您,如果您还有其他问题,欢迎继续提问!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值