我试图制作一张自动幻灯片,图片从右向左滑动。我正在使用css动画属性这样做,它工作正常,溢出的图像(不能适合div)不显示,除非它们可以适合div(获取溢出)。
我尝试与此页面http://merceza.ba/进行类似。
我该如何解决这个问题,是否有任何关于改进我的代码的建议?
#slideshow {
position: absolute;
height: 50%;
overflow: hidden;
margin: 50px auto;
padding: 5px;
background: white;
animation: mymove 5s infinite;
display: inline-block;
}
@keyframes mymove {
from {
left: 0px;
}
to {
left: -50%;
}
}
#slideshow img {
height: 100%;
display: inline-block;
}

<div id="slideshow">
<img id="img1" src="http://merceza.ba/assets/Uploads/_resampled/croppedimage960430-104460427800131820417953145028972251922699o.jpg" alt="1" />
<img id="img2" src="http://merceza.ba/assets/Uploads/_resampled/croppedimage960430-1280604010428385624259212436923590074138462n2.jpg" alt="2" />
<img id="img3" src="http://merceza.ba/assets/Uploads/_resampled/croppedimage960430-104314338351551398609326633168164979199746n2.jpg" alt="3" />
</div>
&#13;
答案 0 :(得分:2)
您可以使用Bootstrap轮播
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h2>Carousel Example</h2>
<div id="myCarousel" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#myCarousel" data-slide-to="0" class="active"></li>
<li data-target="#myCarousel" data-slide-to="1"></li>
<li data-target="#myCarousel" data-slide-to="2"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner">
<div class="item active">
<img src="http://via.placeholder.com/350x150" alt="Los Angeles" style="width:100%;">
</div>
<div class="item">
<img src="http://via.placeholder.com/350x150" alt="Chicago" style="width:100%;">
</div>
<div class="item">
<img src="http://via.placeholder.com/350x150" alt="New york" style="width:100%;">
</div>
</div>
<!-- Left and right controls -->
<a class="left carousel-control" href="#myCarousel" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#myCarousel" data-slide="next">
<span class="glyphicon glyphicon-chevron-right"></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>
</body>
</html>
您可以在此处查看https://getbootstrap.com/docs/4.0/components/carousel/
答案 1 :(得分:0)
这里是使用您自己的方法的解决方案,但在最后一个之后再添加第一张图片,并相应地调整其他设置(容器宽度400%,自动化从0到-300%,图像宽度25%等):
必须调整容器的高度......
#slideshow {
position: absolute;
height: 70%;
width: 400%;
overflow: hidden;
margin: 50px auto;
padding: 0px;
background: white;
animation: mymove 5s linear infinite;
display: inline-block;
font-size: 0;
}
@keyframes mymove {
from {
left: 0%;
}
to {
left: -300%;
}
}
#slideshow img {
height: auto;
width: 25%;
display: inline;
overflow: visible;
}
&#13;
<div id="slideshow">
<img id="img1" src="http://merceza.ba/assets/Uploads/_resampled/croppedimage960430-104460427800131820417953145028972251922699o.jpg" alt="1" />
<img id="img2" src="http://merceza.ba/assets/Uploads/_resampled/croppedimage960430-1280604010428385624259212436923590074138462n2.jpg" alt="2" />
<img id="img3" src="http://merceza.ba/assets/Uploads/_resampled/croppedimage960430-104314338351551398609326633168164979199746n2.jpg" alt="3" />
<img id="img4" src="http://merceza.ba/assets/Uploads/_resampled/croppedimage960430-104460427800131820417953145028972251922699o.jpg" alt="4" />
</div>
&#13;