Created
September 6, 2018 00:10
-
-
Save luislobo14rap/9dbb4ceebba0432c9e88445faa0775e9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<!doctype html> | |
<html lang="pt-br"> | |
<head> | |
<meta charset="utf-8" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous"> | |
<title>dCarousel</title> | |
<style> | |
html, body{ | |
height: 100vh; | |
} | |
.flex-container{ | |
align-items: center; | |
display: flex; | |
justify-content: center; | |
} | |
.d-carousel{ | |
background-color: #aaaaaa; | |
width: 100%; | |
align-items: center; | |
display: flex; | |
justify-content: center; | |
} | |
.d-carousel-prev, .d-carousel-next{ | |
float: left; | |
min-height: 1px; | |
user-select: none; | |
width: 10%; | |
} | |
.d-carousel-prev > div, .d-carousel-next > div{ | |
align-items: center; | |
display: flex; | |
justify-content: center; | |
} | |
.d-carousel-prev-btn, .d-carousel-next-btn{ | |
cursor: pointer; | |
} | |
.d-carousel-inner{ | |
float: left; | |
width: 80%; | |
} | |
</style> | |
</head> | |
<body> | |
<div class="flex-container h-100"> | |
<div class="d-carousel"> | |
<div class="d-carousel-prev"> | |
<div style="display: none;"> | |
<div class="d-carousel-prev-btn"> | |
< | |
</div> | |
</div> | |
</div> | |
<div class="d-carousel-inner"> | |
<div class="text-center mx-auto"> | |
AAA<br> | |
AAA<br> | |
AAA<br> | |
AAA<br> | |
AAA | |
</div> | |
</div> | |
<div class="d-carousel-inner" style="display: none;"> | |
<div class="text-center mx-auto"> | |
BBB<br> | |
BBB<br> | |
BBB<br> | |
BBB<br> | |
BBB | |
</div> | |
</div> | |
<div class="d-carousel-inner" style="display: none;"> | |
<div class="text-center mx-auto"> | |
CCC<br> | |
CCC<br> | |
CCC<br> | |
CCC<br> | |
CCC | |
</div> | |
</div> | |
<div class="d-carousel-inner" style="display: none;"> | |
<div class="text-center mx-auto"> | |
DDD<br> | |
DDD<br> | |
DDD<br> | |
DDD<br> | |
DDD | |
</div> | |
</div> | |
<div class="d-carousel-inner" style="display: none;"> | |
<div class="text-center mx-auto"> | |
EEE<br> | |
EEE<br> | |
EEE<br> | |
EEE<br> | |
EEE | |
</div> | |
</div> | |
<div class="d-carousel-next"> | |
<div> | |
<div class="d-carousel-next-btn"> | |
> | |
</div> | |
</div> | |
</div> | |
</div> | |
</div> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script> | |
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script> | |
<script> | |
$(function() { | |
dCarousel('.d-carousel'); | |
function dCarousel(carousels) { | |
if (typeof carousels == 'string') { | |
carousels = $(carousels); | |
}; | |
carousels.each(function() { | |
let thisCarousel = $(this), | |
prevBtn = thisCarousel.children().first().children(), | |
nextBtn = thisCarousel.children().last().children(); | |
thisCarousel.addClass('active'); | |
thisCarousel.on('click', '.d-carousel-prev-btn', function() { | |
let activated = thisCarousel.find('.d-carousel-inner:visible'), | |
prevInner = activated.prev(); | |
if (prevInner.hasClass('d-carousel-inner')) { | |
activated.css('display', 'none'); | |
prevInner.css('display', 'block'); | |
nextBtn.css('display', 'flex'); | |
if (prevInner.prev().hasClass('d-carousel-inner')) { | |
prevBtn.css('display', 'flex'); | |
} else { | |
prevBtn.css('display', 'none'); | |
}; | |
}; | |
}); | |
thisCarousel.on('click', '.d-carousel-next-btn', function() { | |
let activated = thisCarousel.find('.d-carousel-inner:visible'), | |
nextInner = activated.next(); | |
if (nextInner.hasClass('d-carousel-inner')) { | |
activated.css('display', 'none'); | |
nextInner.css('display', 'block'); | |
prevBtn.css('display', 'flex'); | |
if (nextInner.next().hasClass('d-carousel-inner')) { | |
nextBtn.css('display', 'flex'); | |
} else { | |
nextBtn.css('display', 'none'); | |
}; | |
}; | |
}); | |
}); | |
}; | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment