Incrementally "scroll" container left/right on click with pure css -
i trying create pure css solution scroll set of elements incrementally right or left fixed value on click of href link. have basics working in can scroll right or left on click of corresponding button subsequent clicks toggle between initial positions. cannot increment multiple times left or right.
remember, goal pure css please trying either render working poc or show javascript required can't done pure 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 ); }
create new anchors each scrolled position:
html
<a class="pos" id="pos1"></a> <a class="pos" id="pos2"></a> <a class="pos" id="pos3"></a> <a class="pos" id="pos4"></a>
css
#pos1:target ~ .f-slideshow .items {transform: translatex( 0px );} #pos2:target ~ .f-slideshow .items {transform: translatex( -50px );} #pos3:target ~ .f-slideshow .items {transform: translatex( -100px );} #pos4:target ~ .f-slideshow .items {transform: translatex( -150px );}
use multiple anchors left , right buttons, set position absolute 1 appears @ time.
point them each "position" anchor.
use z-index: 1;
first left , first right buttons:
html
<a class="left" id="left1" href="#pos1"><</a> <a class="left" id="left2" href="#pos2"><</a> <a class="left" id="left3" href="#pos3"><</a> <a class="right" id="right1" href="#pos2">></a> <a class="right" id="right2" href="#pos3">></a> <a class="right" id="right3" href="#pos4">></a>
css
.left, .right { position: absolute; } .right { left: 135px; } #left1, #right1 { z-index: 1; }
change z-index
of appropriate left or right button, depending on scrolled position:
css
#pos1:target ~ #left1, #pos1:target ~ #right1, #pos2:target ~ #left1, #pos2:target ~ #right2, #pos3:target ~ #left2, #pos3:target ~ #right3, #pos4:target ~ #left3, #pos4:target ~ #right3 { z-index: 1; }
Comments
Post a Comment