用html写一个可以滚动播放6张图片,鼠标放上去停止滚动,移开鼠标后继续滚动,可点击把图片放大,放大至全屏,点击关闭放大的展示效果
时间: 2023-09-30 07:05:25 浏览: 133
以下是一个简单的实现滚动播放6张图片的 HTML 代码,并且包含了鼠标悬停暂停和点击放大的功能。你可以根据需要进行修改和扩展。
```html
<!DOCTYPE html>
<html>
<head>
<title>滚动播放图片</title>
<style type="text/css">
#slider {
position: relative;
width: 600px;
height: 400px;
overflow: hidden;
margin: 0 auto;
}
#slider ul {
position: absolute;
top: 0;
left: 0;
width: 3600px;
height: 400px;
margin: 0;
padding: 0;
list-style: none;
animation: slide 10s linear infinite;
}
#slider ul li {
float: left;
width: 600px;
height: 400px;
background-size: cover;
background-repeat: no-repeat;
background-position: center;
}
#slider ul li:hover {
animation-play-state: paused;
}
#slider ul li img {
width: 100%;
height: 100%;
display: none;
position: fixed;
top: 0;
left: 0;
z-index: 9999;
}
#slider ul li img.show {
display: block;
}
#close-btn {
position: fixed;
top: 20px;
right: 20px;
cursor: pointer;
z-index: 9999;
}
@keyframes slide {
0% { transform: translateX(0); }
16.67% { transform: translateX(-600px); }
33.33% { transform: translateX(-1200px); }
50% { transform: translateX(-1800px); }
66.67% { transform: translateX(-2400px); }
83.33% { transform: translateX(-3000px); }
100% { transform: translateX(-3600px); }
}
</style>
</head>
<body>
<div id="slider">
<ul>
<li style="background-image: url('image1.jpg');"></li>
<li style="background-image: url('image2.jpg');"></li>
<li style="background-image: url('image3.jpg');"></li>
<li style="background-image: url('image4.jpg');"></li>
<li style="background-image: url('image5.jpg');"></li>
<li style="background-image: url('image6.jpg');"></li>
</ul>
</div>
<script type="text/javascript">
var slider = document.getElementById('slider');
var images = slider.getElementsByTagName('li');
var closeBtn = document.createElement('div');
closeBtn.id = 'close-btn';
closeBtn.innerHTML = '关闭';
closeBtn.style.display = 'none';
document.body.appendChild(closeBtn);
for (var i = 0; i < images.length; i++) {
images[i].onclick = function() {
var img = document.createElement('img');
img.src = this.style.backgroundImage.replace(/url\("(.*)"\)/, '$1');
img.className = 'show';
document.body.appendChild(img);
closeBtn.style.display = 'block';
}
}
closeBtn.onclick = function() {
var img = document.getElementsByClassName('show')[0];
document.body.removeChild(img);
closeBtn.style.display = 'none';
}
</script>
</body>
</html>
```
注:上述代码中需要替换为你自己的图片路径。
阅读全文