Image carousel widget improvements
This commit is contained in:
parent
2483c6d612
commit
af11358a76
3 changed files with 32 additions and 7 deletions
|
@ -1,8 +1,16 @@
|
||||||
.carousel {
|
.carousel {
|
||||||
height: 100%;
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
overflow: hidden;
|
||||||
background-color: black;
|
background-color: black;
|
||||||
background-size: auto 100%;
|
color: #999;
|
||||||
background-position: center;
|
}
|
||||||
background-repeat: no-repeat;
|
|
||||||
|
.carousel > img {
|
||||||
|
flex-shrink: 0;
|
||||||
|
max-height: 100%;
|
||||||
|
border-radius: 10px;
|
||||||
|
height: 22.5em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
var $imgElement = $('.image-carousel').find('.carousel'),
|
var $imgContainer = $('.image-carousel').find('.carousel'),
|
||||||
config = window.widgets['image-carousel'],
|
config = window.widgets['image-carousel'],
|
||||||
images = config.imageUrls,
|
images = config.imageUrls,
|
||||||
processedImages = 0;
|
processedImages = 0;
|
||||||
|
@ -14,7 +14,22 @@ $(document).ready(function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
var refreshImage = function() {
|
var refreshImage = function() {
|
||||||
$imgElement.css('background-image', "url('" + images[processedImages++] + "')");
|
var $oldImg = $imgContainer.find('img');
|
||||||
|
var $newImg = $imgContainer.find('img').clone()
|
||||||
|
.attr('src', images[processedImages++])
|
||||||
|
.hide().appendTo($imgContainer);
|
||||||
|
|
||||||
|
if ($newImg.width() > $newImg.height()) {
|
||||||
|
$newImg.css('min-width', '100%');
|
||||||
|
} else {
|
||||||
|
$newImg.css('min-width', '');
|
||||||
|
}
|
||||||
|
|
||||||
|
$newImg.on('load', function() {
|
||||||
|
$oldImg.remove();
|
||||||
|
$newImg.fadeIn();
|
||||||
|
});
|
||||||
|
|
||||||
if (processedImages == images.length-1) {
|
if (processedImages == images.length-1) {
|
||||||
shuffleImages();
|
shuffleImages();
|
||||||
processedImages = 0;
|
processedImages = 0;
|
||||||
|
|
|
@ -8,5 +8,7 @@
|
||||||
window.widgets['image-carousel'].imageUrls = {{ images|safe }};
|
window.widgets['image-carousel'].imageUrls = {{ images|safe }};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="carousel"></div>
|
<div class="carousel">
|
||||||
|
<img alt="Your carousel images">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue