纯CSS滑块与自动播放和导航

时间:2015-06-25 05:07:57

标签: html css html5 css3 css-animations

有人知道你是否可以做一个滑块,纯粹的CSS,没有javascript,没有jquery,没有什么,只有一些经典的html5和可能的css3,它必须有自动播放和导航?

我已经使用“关键帧”创建了一个自动播放,但我在制作导航时遇到了一些麻烦。

HTML:

<!doctype html>
<html>
<head>
<meta charset="UTF-8"/>
<title>Slider</title>
<link rel="stylesheet" type="text/css" href="css/style.css"/>
</head>
<body>
<div id="slider">
<ul class="slider-content">
<li style="background:#CCC;"><a href="#">Slide 1</a></li>
<li style="background:#AAA;"><a href="#">Slide 2</a></li>
<li style="background:#333;"><a href="#">Slide 3</a></li>
<li style="background:#666;"><a href="#">Slide 4</a></li>
<li style="background:#999;"><a href="#">Slide 5</a></li>
</ul>
<table>
<tr>
<td><a href="#slide-1"></a></td>
<td><a href="#slide-2"></a></td>
<td><a href="#slide-3"></a></td>
<td><a href="#slide-4"></a></td>
<td><a href="#slide-5"></a></td>
</tr>
</table>
</div>
</body>
</html>

CSS:

.slider-content , .slider-content li 
{
width: 800px;
height: 300px;
}

.slider-content 
{
overflow: hidden;
list-style: none;
padding: 0;
margin: 0;
white-space: nowrap;
border-radius: 3px;
word-spacing: -2px; /* removing inline elements spacing */
letter-spacing: -2px;
}

.slider-content li {
display: inline-block;
word-spacing: normal; /* restoring spacing */
letter-spacing: normal;
}

@keyframes slider {
0%, 17% {margin-left: 0;}
19%, 36% {margin-left: -100%;}
38%, 55% {margin-left: -200%;}
57%, 74% {margin-left: -300%;}
76%, 94% {margin-left: -400%;}
95% {margin-left: -300%;}
96% {margin-left: -200%;}
97% {margin-left: -100%;}
98%, 100% {margin-left: 0;}
}

@-webkit-keyframes slider {
0%, 17% {margin-left: 0;}
19%, 36% {margin-left: -100%;}
38%, 55% {margin-left: -200%;}
57%, 74% {margin-left: -300%;}
76%, 94% {margin-left: -400%;}
95% {margin-left: -300%;}
96% {margin-left: -200%;}
97% {margin-left: -100%;}
98%, 100% {margin-left: 0;}
}

.slider-content li:first-child {
-webkit-animation: slider 20s ease-out infinite;
animation: slider 20s ease-out infinite;
}

0 个答案:

没有答案