From 1388552a888c1c0f597475b5356904d7c6e84fd7 Mon Sep 17 00:00:00 2001 From: Mihai Georgescu Date: Wed, 3 Apr 2013 17:17:28 +0100 Subject: [PATCH 1/2] Added custom events fired when slide changes --- README.md | 19 +++++++++++++++---- simple.carousel.js | 6 +++++- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index cd49af6..d598450 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ simple.carousel Copyright (c) 2012 Tobias Zeising, http://www.aditu.de Licensed under the MIT license -Version 0.3 +Version 0.3.1 This is a simple jQuery plugin for creating sliding carousels. @@ -15,7 +15,6 @@ Demo/Examples [aditu.de (image will change using a fade in/fade out effect)](http://www.aditu.de/)
[rsslounge (presentation of the features by an slideshow)](http://rsslounge.aditu.de/)
- Usage ----- @@ -63,7 +62,7 @@ Parameters parametertypeoutcome - wdithintwidth of the single frames + widthintwidth of the single frames heightintheight of the frames @@ -92,6 +91,9 @@ Parameters paginationintset true for this value and a pagination element will be included + + slideeventstringcustom event name fired when slide changes; see Slide Event example + @@ -107,4 +109,13 @@ $("#carousel").simplecarousel({ }); -Will create a carousel with fadein/fadeout effect. The pause between two frames will be 4 seconds, the speed of the fade effect will be 400 ms, the element with the class 'next' will be the next button (the same with 'prev' for back button). See download for further examples. \ No newline at end of file +Will create a carousel with fadein/fadeout effect. The pause between two frames will be 4 seconds, the speed of the fade effect will be 400 ms, the element with the class 'next' will be the next button (the same with 'prev' for back button). See download for further examples. + +Slide Event example +-------- +The following will log the current slide index and the direction. +
+$("#carousel").on('slide', function(e, config, dir){
+    console.log(config.current + ' ' + dir);
+});
+
\ No newline at end of file diff --git a/simple.carousel.js b/simple.carousel.js index 05badd2..037c910 100644 --- a/simple.carousel.js +++ b/simple.carousel.js @@ -21,7 +21,8 @@ $.fn.simplecarousel = function( params ) { items: 0, slidespeed: 600, visible: 1, - pagination: false + pagination: false, + slideevent: 'slide' //custom event name to be triggered }; var config = $.extend(defaults, params); @@ -103,6 +104,9 @@ $.fn.simplecarousel = function( params ) { setTimeout(function() { slide('next'); }, config.auto); + + //fire a custom event on the original element, sends the current config and direction + ul.trigger(config.slideevent, [config, dir]); } // include pagination From 43a8f1f4b3cc4476f45f65712a555f88230a1767 Mon Sep 17 00:00:00 2001 From: Mihai Georgescu Date: Tue, 28 May 2013 13:44:24 +0100 Subject: [PATCH 2/2] You can now call slide on the carousel --- simple.carousel.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/simple.carousel.js b/simple.carousel.js index 037c910..bc962dc 100644 --- a/simple.carousel.js +++ b/simple.carousel.js @@ -60,7 +60,7 @@ $.fn.simplecarousel = function( params ) { }); // function for sliding the carousel - var slide = function(dir, click) { + var slide = this.slide = function(dir, click) { if(typeof click == "undefined" & config.auto==false) return; @@ -144,5 +144,6 @@ $.fn.simplecarousel = function( params ) { setTimeout(function() { slide('next'); }, config.auto); + return this; } })(jQuery); \ No newline at end of file