JQuery Karussell: Unterschied zwischen den Versionen
Aus VICON-Wiki
(Die Seite wurde neu angelegt: „Kategorie:Javascript:Snippets == Einleitung == Rapid Data benutzt in ihren Layouts oft ein Karussel in dem drei Bilder nebeneinander Dargestellt werden, wo…“) |
|||
| Zeile 22: | Zeile 22: | ||
<?php endforeach; ?> | <?php endforeach; ?> | ||
<?php endforeach; ?> | <?php endforeach; ?> | ||
| + | <div class="carousel-next"><i class="fa fa-chevron-right"></i></div> | ||
| + | <div class="carousel-prev"><i class="fa fa-chevron-left"></i></div> | ||
</div></nowiki> | </div></nowiki> | ||
=== Script === | === Script === | ||
| Zeile 53: | Zeile 55: | ||
carousel.reload(options); | carousel.reload(options); | ||
showDescription(); | showDescription(); | ||
| + | }); | ||
| + | $(".carousel-next").click(function() { | ||
| + | carousel.next(); | ||
| + | }); | ||
| + | $(".carousel-prev").click(function() { | ||
| + | carousel.prev(); | ||
}); | }); | ||
Version vom 6. März 2015, 10:48 Uhr
Inhaltsverzeichnis
Einleitung
Rapid Data benutzt in ihren Layouts oft ein Karussel in dem drei Bilder nebeneinander Dargestellt werden, wobei das zentrierte größer ist als die äußeren. Dies lässt sich sehr gut mit dem WaterwheelCarousel umsetzen.
Benutzung
Es wird die standard Galerie von Contao benutzt. Dazu müssen wir das Template anpassen und die benötigten Scripte einbinden.
Falls benötigt kann in den Meta-Einstellungen der Bilder noch ein Titel oder die Bildunterschrift angegeben werden. Je nach Bedarf sind dann im HTML-Markup die Klassen carousel-heading, carousel-description oder carousel-menu zu setzen. Ggf. muss dieser Teil des Scripts angepasst werden.
Tempalte
Dateiname: gallery_waterwheelCarousel.html5
<div id="carousel">
<?php $imgCount = 0; ?>
<?php foreach ($this->body as $class=>$row): ?>
<?php foreach ($row as $col): ?>
<?php $imgCount++; ?>
<?php if ($col->addImage): ?>
<img src="<?php echo $col->src; ?>"<?php echo $col->imgSize; ?> title="<?php echo $col->alt; ?>" alt="<?php echo $col->caption; ?>">
<?php endif; ?>
<?php endforeach; ?>
<?php endforeach; ?>
<div class="carousel-next"><i class="fa fa-chevron-right"></i></div>
<div class="carousel-prev"><i class="fa fa-chevron-left"></i></div>
</div>
Script
jQuery(document).ready(function($) {
// Waterwheel carousel
var options = {
flankingItems: 2,
separation: 100,
startingItem: 1,
opacityMultiplier: 1,
preloadImages: false,
movedToCenter: function($newCenter) {
$(".carousel-heading").text($newCenter.attr("title"));
$(".carousel-description").text($newCenter.attr("alt"));
}
}
showDescription();
$("#carousel img").each(function(index) {
$(".carousel-menu").append('<li><a href="#" data-slide="'+ (index+1) +'">' + $(this).attr("title") + '</a></li>');
});
// Initialize the carousel with options above
var carousel = $("#carousel").waterwheelCarousel(options);
$(".carousel-menu a").click(function(e) {
e.preventDefault();
var index = parseInt($(this).attr("data-slide"));
options.startingItem = index;
carousel.reload(options);
showDescription();
});
$(".carousel-next").click(function() {
carousel.next();
});
$(".carousel-prev").click(function() {
carousel.prev();
});
function showDescription() {
var index = options.startingItem;
var $sourceItem = $("#carousel img:nth-child("+ index +")");
$(".carousel-heading").text($sourceItem.attr("title"));
$(".carousel-description").text($sourceItem.attr("alt"));
}
});