如何每隔一段时间移动我的 CSS 滑块?



我有以下代码,我目前正在苦苦挣扎:

<!DOCTYPE html>
<html >
<head>

		<style type="text/css">
@import url(https://fonts.googleapis.com/css?family=Varela+Round);
.slides {
top: 0
px;
width: 100%;
height: 840px;
display: block;
margin: 0 auto;
position: relative;
}
.slides * {
user-select: none;
-ms-user-select: none;
-moz-user-select: none;
-khtml-user-select: none;
-webkit-user-select: none;
-webkit-touch-callout: none;
}
.slides input { display: none; }
.slide-container { display: block; }
.slide {
top: 0;
opacity: 0;
width: 100%;
min-height: 100%;
display: block;
position: absolute;
transform: scale(1);
transition: all .7s ease-in-out;
}
.slide img {
width: 100%;
height: 100%;
}
.nav label {
width: 200px;
height: 100%;
display: none;
position: absolute;
	  opacity: 0;
z-index: 9;
cursor: pointer;
transition: opacity .2s;
color: rgb(255,133,102);
font-size: 156pt;
text-align: center;
line-height: 380%;
font-family: "Varela Round", sans-serif;
background-color: rgba(255, 255, 255, .3);
text-shadow: 0px 0px 15px rgb(119, 119, 119);
}
.slide:hover + .nav label { opacity: 0.5; }
.nav label:hover { opacity: 1; }
.nav .next { right: 0; }
input:checked + .slide-container  .slide {
opacity: 1;
transform: scale(1);
transition: opacity 1s ease-in-out;

}
input:checked + .slide-container .nav label { display: block; }
.nav-dots {
	width: 100%;
	bottom: 9px;
	height: 11px;
	left:90px;
	display: block;
	position: absolute;
	text-align: center;
}
.nav-dots .nav-dot {
	top: -5px;
	width: 11px;
	height: 11px;
	margin: 0 4px;
	position: relative;
	border-radius: 100%;
	display: inline-block;
	background-color: rgba(255, 0, 0, 0.6);
}
.nav-dots .nav-dot:hover {
	cursor: pointer;
	background-color: rgba(255, 0, 0, 0.8);
}
input#img-1:checked ~ .nav-dots label#img-dot-1,
input#img-2:checked ~ .nav-dots label#img-dot-2,
input#img-3:checked ~ .nav-dots label#img-dot-3,
input#img-4:checked ~ .nav-dots label#img-dot-4,
input#img-5:checked ~ .nav-dots label#img-dot-5,
input#img-6:checked ~ .nav-dots label#img-dot-6 {
	background: rgba(255, 0, 0, 1);
}
}
</style>
</head>
<body>
<ul class="slides">
<input type="radio" name="radio-btn" id="img-1" checked />
<li class="slide-container" >
		<div class="slide">
			<img src="https://cdn.shopify.com/s/files/1/9999/9999/files/Pulpbar_presentation_slide_01.jpg" />
</div>
		<div class="nav">
			<label for="img-6" class="prev">&#x2039;</label>
			<label for="img-2" class="next">&#x203a;</label>
		</div>
</li>
<input type="radio" name="radio-btn" id="img-2" />
<li class="slide-container">
<div class="slide">
<img src="https://cdn.shopify.com/s/files/1/9999/9999/files/ice2.jpg" />
</div>
		<div class="nav">
			<label for="img-1" class="prev">&#x2039;</label>
			<label for="img-3" class="next">&#x203a;</label>
		</div>
</li>
<input type="radio" name="radio-btn" id="img-3" />
<li class="slide-container">
<div class="slide">
<img src="" />
</div>
		<div class="nav">
			<label for="img-2" class="prev">&#x2039;</label>
			<label for="img-4" class="next">&#x203a;</label>
		</div>
</li>
<input type="radio" name="radio-btn" id="img-4" />
<li class="slide-container">
<div class="slide">
<img src="" />
</div>
		<div class="nav">
			<label for="img-3" class="prev">&#x2039;</label>
			<label for="img-5" class="next">&#x203a;</label>
		</div>
</li>
<input type="radio" name="radio-btn" id="img-5" />
<li class="slide-container">
<div class="slide">
<img src="" />
</div>
		<div class="nav">
			<label for="img-4" class="prev">&#x2039;</label>
			<label for="img-6" class="next">&#x203a;</label>
		</div>
</li>
<input type="radio" name="radio-btn" id="img-6" />
<li class="slide-container">
<div class="slide">
<img src="" />
</div>
		<div class="nav">
			<label for="img-5" class="prev">&#x2039;</label>
			<label for="img-1" class="next">&#x203a;</label>
		</div>
</li>
<li class="nav-dots">
<label for="img-1" class="nav-dot" id="img-dot-1"></label>
<label for="img-2" class="nav-dot" id="img-dot-2"></label>
<label for="img-3" class="nav-dot" id="img-dot-3"></label>
<label for="img-4" class="nav-dot" id="img-dot-4"></label>
<label for="img-5" class="nav-dot" id="img-dot-5"></label>
<label for="img-6" class="nav-dot" id="img-dot-6"></label>
</li>
</ul>
</body>
</html>

我想在一定时间内移动到下一个滑块。.nav标签似乎是感兴趣的领域,但不幸的是我无法触发它。任何想法如何工作或关于阅读内容的任何建议?

由于这个问题下的讨论变得有些广泛,以下是您的选择的摘要。

词汇/用例

这是我自己经常在努力的事情 ->用正确的术语命名技术细节。在您的情况下,您询问了带有事件的滑块,它通常是一个输入元素,类似于<input type="range">,但实际上您的意思是"幻灯片"。这让一些用户感到困惑,他们后来离开了这个线程。但无论如何,在发布问题之前,请务必先尝试研究您的用例,并在问题下收到与语言相关的评论时相应地更新它。公平地说,我们现在都知道这个问题是关于css幻灯片的,或者其他人称之为"轮播"。此外,您可以固定一些图像来建议代码的所需结果,以避免无聊的解释。

纯CSS

您要求一个纯CSS幻灯片。这是可以做到的,而且已经经常这样做。在这篇博文中,您可以看到一些臭名昭著的示例,您可以轻松学习甚至直接将其引入代码中。由于您的问题和评论表明您不是真正的高级编码人员,因此我建议您先学习通用的css,然后再学习幻灯片示例。

考虑现成的元素

我不确定你身边的JS有什么问题,但听起来你不是故意避免JS。如果您从编码开始,并且只想打开一些页面。使用某种预先设置样式和预编码的组件库可能会容易得多,这些组件只是在页面中实现。有大量的这些现成的组件,通常称为"材料",例如角度材料。可能最受欢迎的是 Bootstrap>这里是 Bootstrap 的轮播示例。

最新更新