HTML
<div id="carousel"> <div class="page prev"> <div class="img-col" style="background-image:url(https://www.fairr.de/assets/img/testimonials/robert-sasse.jpg)"></div> <div class="text-col"> <div class="hl">Robert Sasse</div> <p>Endlich eine ETF-Rente, die sich sowohl von der Gebührenstruktur als auch von der Rendite für Anleger bezahlt macht.</p> </div> </div> <div class="page active"> <div class="img-col" style="background-image:url(https://www.fairr.de/assets/img/testimonials/robert-sasse.jpg)"></div> <div class="text-col"> <div class="hl">Robert Sasse</div> <p>Endlich eine ETF-Rente, die sich sowohl von der Gebührenstruktur als auch von der Rendite für Anleger bezahlt macht.</p> </div> </div> <div class="page next"> <div class="img-col" style="background-image:url(https://www.fairr.de/assets/img/testimonials/robert-sasse.jpg)"></div> <div class="text-col"> <div class="hl">Robert Sasse</div> <p>Endlich eine ETF-Rente, die sich sowohl von der Gebührenstruktur als auch von der Rendite für Anleger bezahlt macht.</p> </div> </div> <div class="page"> <div class="img-col" style="background-image:url(https://www.fairr.de/assets/img/testimonials/robert-sasse.jpg)"></div> <div class="text-col"> <div class="hl">Robert Sasse</div> <p>Endlich eine ETF-Rente, die sich sowohl von der Gebührenstruktur als auch von der Rendite für Anleger bezahlt macht.</p> </div> </div> </div>
SCSS
body { background: white; color: black; margin: 100px 20px; } .fpcarousel { height: 125px; width: 100%; white-space: nowrap; position: relative; overflow: hidden; .page { height: 125px; width: 70%; position: absolute; display: none; &.transition { transition: all 2000ms ease-in-out; } .img-col { display: inline-block; width: 170px; height: 100%; border-radius: 4px; overflow: hidden; background-size: cover; background-position: center center; vertical-align: top; } .text-col { display: inline-block; width: calc(100% - 170px); height: 100%; vertical-align: top; white-space: normal; box-sizing: border-box; padding: 15px 30px; .hl { font-size: 20px; } } &.active { left: 15%; display: inline-block; opacity: 1; } &.prev { left: -55%; display: inline-block; opacity: .25; } &.next { left: 85%; display: inline-block; opacity: .25; } &.prev2 { left: -125%; display: inline-block; opacity: 0; } &.next2 { left: 155%; display: inline-block; opacity: 0; } } }
Script
!function($) { var FpCarousel = function($element, options) { this.$e = $element.addClass('fpcarousel'); this.$page = this.$e.find('.page'); this.options = options || {}; this.interval = this.options.interval || 5000; this.$page.on('transitionend webkitTransitionEnd oTransitionEnd', function() { $(this).removeClass('transition'); console.log('transition ended'); }); //setInterval($.proxy(this.nextPage, this), this.interval); setInterval($.proxy(this.nextPage, this), 2500); }; $.extend(FpCarousel.prototype, { constructor: FpCarousel, nextPage: function() { var $prev = this.$page.filter('.prev'), $active = this.$page.filter('.active'), $next = this.$page.filter('.next'), $next2 = this.after($next); $prev.addClass('transition').addClass('prev2').removeClass('prev'); $active.addClass('transition prev').removeClass('active'); $next.addClass('transition active').removeClass('next'); $next2.removeClass('transition prev2').addClass('next2'); setTimeout(function() { $next2.addClass('transition next').removeClass('next2'); }, 0); }, after: function($page) { var $next = $page.next('.page'); return $next.length ? $next : $(this.$page.get(0)); } }); $.fn.fpcarousel = function(a, b, c) { return this.each(function() { var $this = $(this), $obj = $this.data('fpcarousel'), options = typeof a === 'object' && a; if (!$obj) { $this.data('fpcarousel', ($obj = new FpCarousel($this, a))); } }); }; }(window.jQuery); $('#carousel').fpcarousel();