A Pen by Elias Reyes on CodePen.
Created
February 5, 2019 04:47
-
-
Save avxkim/dc74d5a73705169eb91f4bcaf4f06e7c to your computer and use it in GitHub Desktop.
Simple Horizontal Slider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1>Horizontal Slider</h1> | |
<h4>En desarollo</h4> | |
<hr /> | |
<div class="horizontal-slider"> | |
<ul class="h-items"> | |
<li>1</li> | |
<li>2</li> | |
<li>3</li> | |
</ul> | |
<div class="h-controlls"> | |
<span class="prev"> | |
<i class="fa fa-chevron-left" aria-hidden="true"></i> | |
</span> | |
<span class="next"> | |
<i class="fa fa-chevron-right" aria-hidden="true"></i> | |
</span> | |
</div> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var hsuma = 0; | |
$(document).ready(function(){ | |
$(".next").click(function(){ | |
hsuma += -100; | |
if(hsuma>=-200) | |
$(".h-items").animate({marginLeft:hsuma+"%"},"fast"); | |
else{ | |
hsuma = 0; | |
$(".h-items").animate({marginLeft:hsuma+"%"},"fast"); | |
} | |
}); | |
$(".prev").click(function(){ | |
if(hsuma==0){ | |
hsuma = -200; | |
$(".h-items").animate({marginLeft:hsuma+"%"},"fast"); | |
} | |
else{ | |
hsuma += 100; | |
$(".h-items").animate({marginLeft:hsuma+"%"},"fast"); | |
} | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script> | |
<script src="https://use.fontawesome.com/42649e5898.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body, | |
html { | |
width: 100%; | |
height: 100%; | |
margin: 0px; | |
padding: 20px; | |
font-family: arial; | |
box-sizing:border-box; | |
} | |
.horizontal-slider { | |
width: 500px; | |
height: 150px; | |
background: #e6e6e6; | |
overflow: hidden; | |
position: relative; | |
} | |
.h-items { | |
width: 300%; | |
font-size: 0; | |
list-style-none; | |
margin: 0; | |
padding: 0; | |
box-sizing: border-box; | |
position: relative; | |
} | |
.h-items>li { | |
display: inline-block; | |
font-size: 12pt; | |
width: 33.33%; | |
padding: 10px; | |
box-sizing: border-box; | |
position: relative; | |
} | |
.prev, | |
.next { | |
position: absolute; | |
top: 50%; | |
transform: translateY(-50%); | |
padding: 10px; | |
cursor: pointer; | |
} | |
.next { | |
right: 0px; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment