我想創建一個純粹的CSS解決方案,將增量滾動一組元素的權利或留下一些固定值點擊一個href鏈接。我有基本的工作,我可以滾動向右或向左點擊相應的按鈕,但隨後的點擊只在初始位置之間切換。我無法多次向左或向右遞增。遞增「滾動」容器左/右用純CSS點擊
請記住,目標是純粹的CSS,因爲我想要呈現工作POC或顯示JavaScript將被要求,因爲這不能用純CSS完成。
http://plnkr.co/edit/itGDeyE8sfXtEbhBlycJ?p=preview
HTML
<head>
<link rel="stylesheet" href="style.css">
<script src="script.js"></script>
</head>
<body>
<a id="left" href="#left"><</a>
<a id="right" href="#right">></a>
<div class="f-slideshow">
<div class="items">
<span>1</span>
<span>2</span>
<span>3</span>
<span>4</span>
<span>5</span>
<span>6</span>
<span>7</span>
<span>8</span>
</div>
</div>
</body>
</html>
CSS
.f-slideshow{
position:relative;
max-width:100px;
overflow:hidden;
display:inline-block;
}
.f-slideshow .items{
display:inline-table;
overflow:hidden;
width:100%;
background:#999;
position:relative;
box-sizing: border-box;
-webkit-transition: -webkit-transform 0.6s ease-in-out;
transition: transform 0.6s ease-in-out;
}
.f-slideshow span{
margin:3px;
padding:5px;
background:#ddd;
border-radius:3px;
}
#right {
position: relative;
left: 125px;
}
#right:target ~ .f-slideshow .items{
transform: translateX(-50px);
}
#left:target ~ .f-slideshow .items{
transform: translateX(0px);
}
你可以添加額外的HTML? –
是的,但只要右側或左側滾動仍然是隻有兩個元素的領域(我不能有N個錨定標籤來定位N個物品) – mccainz
這樣的事情? http://webdesign.tutsplus.com/tutorials/how-to-create-an-anything-slider-with-just-css--cms-24278 –