(function ($, window, undefined) {
'use strict';
$.Carousel = function (element) {
this.$el = $(element);
};
$.Carousel.prototype = {
_init: function () { //Init The Plugin
this._layout();
this._initEvents();
this.autoPlay();
},
_layout: function () { //Map the Layout of the Menu
this.pages = this.$el.children('.column');
this.pagesLength = this.pages.length;
this.activePage = this.$el.children('.active');
this.nextPage = this.$el.children('.next');
this.prevPage = this.$el.children('.prev');
},
autoPlay: function () {
var self = this;
var play = setInterval(function () {
self._page(+1); // same as clicking next
}, 3000); // every 3 seconds
$('.mobile-carousel').hover(function () { // when mouse is over carousel
clearInterval(play); // clearInterval to pause
}, function () { // when mouse is not over carousel
play = setInterval(function () { // setInterval again to resume playing
self._page(+1);
}, 3000);
});
},
_initEvents: function () { //Set Up the Event Listeners
var self = this;
this.nextPage.on('click.carousel', function (e) {
self._page(+1);
e.preventDefault();
});
this.prevPage.on('click.carousel', function (e) {
self._page(-1);
e.preventDefault();
});
},
_page: function (delta) {
var index = this.activePage.index() + delta,
length = (this.pagesLength - 1);
if (index < 0) {
index = length;
}
if (index > length) {
index = 0;
}
this._animatePage(this.activePage,...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.