我想自动制作此滑块,同时按顺序在提供的六边形上旋转图像。此外,应将第一张图像添加到背景中,然后添加到六边形,直到它返回。
如何使用JavaScript和CSS执行此操作?
我试图在没有任何箭头的情况下使滑块清洁,但需要通过单击六边形来支持导航。如果单击六边形,则形状上的图像会自动转移到背景,同时自动将剩余的形状切换到其位置。
$("#hexGrid > ul:gt(0)").hide();
setInterval(function() {
$("#hexGrid > ul:first")
.fadeOut(1000)
.next()
.fadeIn(1000)
.end()
.appendTo("#hexGrid");
}, 3000);
#hexGrid {
display: flex;
left: 75px;
flex-wrap: wrap;
width: 45%;
overflow: hidden;
font-family: 'Raleway', sans-serif;
font-size: 12px;
list-style-type: none;
}
#hexGrid>ul {
display: flex;
left: 75px;
flex-wrap: wrap;
width: 45%;
overflow: hidden;
font-family: 'Raleway', sans-serif;
font-size: 12px;
list-style-type: none;
}
.hex {
position: relative;
top: 25px;
visibility: hidden;
outline: 1px solid transparent;
/* fix for jagged edges in FF on hover transition */
}
.hex::after {
content: '';
display: block;
padding-bottom: 86.602%;
/* = 100 / tan(60) * 1.5 */
}
.hexIn {
position: absolute;
width: 96%;
padding-bottom: 110.851%;
/* = width / sin(60) */
margin: 0 2%;
overflow: hidden;
visibility: hidden;
outline: 1px solid transparent;
/* fix for jagged edges in FF on hover transition */
-webkit-transform: rotate3d(0, 0, 1, -60deg) skewY(30deg);
-ms-transform: rotate3d(0, 0, 1, -60deg) skewY(30deg);
transform: rotate3d(0, 0, 1, -60deg) skewY(30deg);
}
.hexIn * {
position: absolute;
visibility: visible;
outline: 1px solid transparent;
/* fix for jagged edges in FF on hover transition */
}
.hexLink {
display: block;
width: 100%;
height: 100%;
text-align: center;
color: #fff;
overflow: hidden;
-webkit-transform: skewY(-30deg) rotate3d(0, 0, 1, 60deg);
-ms-transform: skewY(-30deg) rotate3d(0, 0, 1, 60deg);
transform: skewY(-30deg) rotate3d(0, 0, 1, 60deg);
}
/*** HEX CONTENT **********************************************************************/
.hex img {
left: -100%;
right: -100%;
width: auto;
height: 100%;
margin: 0 auto;
-webkit-transform: rotate3d(0, 0, 0, 0deg);
-ms-transform: rotate3d(0, 0, 0, 0deg);
transform: rotate3d(0, 0, 0, 0deg);
}
.hex h1,
.hex p {
width: 100%;
padding: 5%;
box-sizing: border-box;
background-color: rgba(45, 87, 47, 0.2);
font-weight: 300;
-webkit-transition: -webkit-transform .2s ease-out, opacity .3s ease-out;
transition: transform .2s ease-out, opacity .3s ease-out;
}
.hex h1 {
bottom: 50%;
padding-top: 50%;
font-size: 1.7em;
z-index: 1;
-webkit-transform: translate3d(0, -100%, 0);
-ms-transform: translate3d(0, -100%, 0);
transform: translate3d(0, -100%, 0);
}
.hex h1::after {
content: '';
position: absolute;
bottom: 0;
left: 45%;
width: 10%;
text-align: center;
border-bottom: 1px solid #fff;
}
.hex p {
top: 50%;
padding-bottom: 50%;
-webkit-transform: translate3d(0, 100%, 0);
-ms-transform: translate3d(0, 100%, 0);
transform: translate3d(0, 100%, 0);
font-size: 1.5em;
}
/*** HOVER EFFECT **********************************************************************/
.hexLink:hover h1,
.hexLink:focus h1,
.hexLink:hover p,
.hexLink:focus p {
-webkit-transform: translate3d(0, 0, 0);
-ms-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
}
/*** HEXAGON SIZING AND EVEN ROW INDENTATION *****************************************************************/
@media (min-width:1201px) {
/* <- 5-4 hexagons per row */
#hexGrid {
padding-bottom: 7.4%
}
.hex {
width: 33.333%;
/* = 100 / 3 */
}
.hex:nth-child(5n+4) {
/* first hexagon of even rows */
margin-left: 16.666%;
/* = width of .hex / 2 to indent even rows */
}
}
@media (max-width: 1200px) and (min-width:901px) {
/* <- 4-3 hexagons per row */
#hexGrid {
padding-bottom: 7.4%
}
.hex {
width: 33.333%;
/* = 100 / 3 */
}
.hex:nth-child(5n+4) {
/* first hexagon of even rows */
margin-left: 16.666%;
/* = width of .hex / 2 to indent even rows */
}
}
@media (max-width: 900px) and (min-width:601px) {
/* <- 3-2 hexagons per row */
#hexGrid {
padding-bottom: 7.4%
}
.hex {
width: 33.333%;
/* = 100 / 3 */
}
.hex:nth-child(5n+4) {
/* first hexagon of even rows */
margin-left: 16.666%;
/* = width of .hex / 2 to indent even rows */
}
}
@media (max-width: 600px) {
/* <- 2-1 hexagons per row */
#hexGrid {
padding-bottom: 11.2%
}
.hex {
width: 50%;
/* = 100 / 3 */
}
.hex:nth-child(3n+3) {
/* first hexagon of even rows */
margin-left: 25%;
/* = width of .hex / 2 to indent even rows */
}
}
@media (max-width: 400px) {
#hexGrid {
font-size: 13px;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul class="side-hexagon" id="hexGrid">
<li class="hex">
<div> </div>
<div class="hexIn">
<a class="hexLink" href="#">
<img src="//farm6.static.flickr.com/5224/5658667829_2bb7d42a9c_m.jpg" alt="" />
<h1>This is a title</h1>
<p>View</p>
<data style="display:none">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque malesuada non
diam non egestas. Etiam vulputate ipsum vel est finibus molestie id eget mauris.</data>
</a>
</div>
</li>
<li class="hex">
<div class="hexIn">
<a class="hexLink" href="#">
<img src="//farm6.static.flickr.com/5224/5658667829_2bb7d42a9c_m.jpg" alt="" />
<h1>Agency Banking</h1>
<p>View</p>
<data style="display:none" font color="black">With over 100 agents Agribank provides the best banking network</data>
</a>
</div>
</li>
<li class="hex">
<div class="hexIn">
<a class="hexLink" href="#">
<img src="//farm6.static.flickr.com/5224/5658667829_2bb7d42a9c_m.jpg" alt="" />
<h1>This is a title</h1>
<p>View</p>
<data style="display:none">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque malesuada non
diam non egestas. Etiam vulputate ipsum vel est finibus molestie id eget mauris.</data>
</a>
</div>
</li>
<li class="hex">
<div class="hexIn">
<a class="hexLink" href="#">
<img src="//farm6.static.flickr.com/5230/5638093881_a791e4f819_m.jpg" alt="" />
<h1>This is a title</h1>
<p>View</p>
<data style="display:none">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque malesuada non
diam non egestas. Etiam vulputate ipsum vel est finibus molestie id eget mauris.</data>
</a>
</div>
</li>
<li class="hex">
<div class="hexIn">
<a class="hexLink" href="#">
<img src="//farm6.static.flickr.com/5230/5638093881_a791e4f819_m.jpg" alt="" />
<h1>This is a title</h1>
<p>View</p>
<data style="display:none">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque malesuada non
diam non egestas. Etiam vulputate ipsum vel est finibus molestie id eget mauris.</data>
</a>
</div>
</li>
<li class="hex">
<div class="hexIn">
<a class="hexLink" href="#">
<img src="//farm6.static.flickr.com/5230/5638093881_a791e4f819_m.jpg" alt="" />
<h1>AgriSave</h1>
<p>View</p>
<data style="display:none">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque malesuada non
diam non egestas. Etiam vulputate ipsum vel est finibus molestie id eget mauris.</data>
</a>
</div>
</li>
<li class="hex">
<div class="hexIn">
<a class="hexLink" href="#">
<img src="//farm6.static.flickr.com/5230/5638093881_a791e4f819_m.jpg" alt="" />
<h1>KidSave</h1>
<p>View</p>
<data style="display:none">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque malesuada non
diam non egestas. Etiam vulputate ipsum vel est finibus molestie id eget mauris.</data>
</a>
</div>
</li>
<li class="hex">
<div class="hexIn">
<a class="hexLink" href="#">
<img src="//farm6.static.flickr.com/5230/5638093881_a791e4f819_m.jpg" alt="" />
<h1>Shades of Green</h1>
<p>View</p>
<data style="display:none">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque malesuada non
diam non egestas. Etiam vulputate ipsum vel est finibus molestie id eget mauris.</data>
</a>
</div>
</li>
</ul>