├── .gitignore ├── images ├── 1.jpg ├── 2.jpg ├── 3.jpg ├── 4.jpg ├── ford.png ├── mini.png ├── ferrari.png ├── logo-hp.png ├── chevrolet.png ├── logo-ebay.png ├── logo-nike.png ├── logo-nyt.png ├── aston-martin.png ├── lamborghini.png ├── logo-adidas.png ├── logo-amazon.png ├── logo-android.png ├── logo-spotify.png ├── logo-youtube.png └── logo-microsoft.png ├── package.json ├── css └── style.css ├── index.html ├── README.md └── js └── jquery.flexisel.js /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | -------------------------------------------------------------------------------- /images/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/9bitStudios/flexisel/HEAD/images/1.jpg -------------------------------------------------------------------------------- /images/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/9bitStudios/flexisel/HEAD/images/2.jpg -------------------------------------------------------------------------------- /images/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/9bitStudios/flexisel/HEAD/images/3.jpg -------------------------------------------------------------------------------- /images/4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/9bitStudios/flexisel/HEAD/images/4.jpg -------------------------------------------------------------------------------- /images/ford.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/9bitStudios/flexisel/HEAD/images/ford.png -------------------------------------------------------------------------------- /images/mini.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/9bitStudios/flexisel/HEAD/images/mini.png -------------------------------------------------------------------------------- /images/ferrari.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/9bitStudios/flexisel/HEAD/images/ferrari.png -------------------------------------------------------------------------------- /images/logo-hp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/9bitStudios/flexisel/HEAD/images/logo-hp.png -------------------------------------------------------------------------------- /images/chevrolet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/9bitStudios/flexisel/HEAD/images/chevrolet.png -------------------------------------------------------------------------------- /images/logo-ebay.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/9bitStudios/flexisel/HEAD/images/logo-ebay.png -------------------------------------------------------------------------------- /images/logo-nike.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/9bitStudios/flexisel/HEAD/images/logo-nike.png -------------------------------------------------------------------------------- /images/logo-nyt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/9bitStudios/flexisel/HEAD/images/logo-nyt.png -------------------------------------------------------------------------------- /images/aston-martin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/9bitStudios/flexisel/HEAD/images/aston-martin.png -------------------------------------------------------------------------------- /images/lamborghini.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/9bitStudios/flexisel/HEAD/images/lamborghini.png -------------------------------------------------------------------------------- /images/logo-adidas.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/9bitStudios/flexisel/HEAD/images/logo-adidas.png -------------------------------------------------------------------------------- /images/logo-amazon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/9bitStudios/flexisel/HEAD/images/logo-amazon.png -------------------------------------------------------------------------------- /images/logo-android.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/9bitStudios/flexisel/HEAD/images/logo-android.png -------------------------------------------------------------------------------- /images/logo-spotify.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/9bitStudios/flexisel/HEAD/images/logo-spotify.png -------------------------------------------------------------------------------- /images/logo-youtube.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/9bitStudios/flexisel/HEAD/images/logo-youtube.png -------------------------------------------------------------------------------- /images/logo-microsoft.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/9bitStudios/flexisel/HEAD/images/logo-microsoft.png -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "flexisel", 3 | "version": "2.2.0", 4 | "description": "A responsive carousel jQuery plugin", 5 | "main": "index.js", 6 | "repository": { 7 | "type": "git", 8 | "url": "git+https://github.com/9bitStudios/flexisel.git" 9 | }, 10 | "keywords": [ 11 | "flexisel", 12 | "images", 13 | "carousel" 14 | ], 15 | "author": "9bitStudios", 16 | "license": "MIT", 17 | "bugs": { 18 | "url": "https://github.com/9bitStudios/flexisel/issues" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /css/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | background:#fff; 3 | font-family:Arial, sans-serif; 4 | } 5 | 6 | p { 7 | margin-bottom:20px; 8 | } 9 | 10 | .clearout { 11 | height:20px; 12 | clear:both; 13 | } 14 | 15 | #flexiselDemo1, #flexiselDemo2, #flexiselDemo3 { 16 | display:none; 17 | } 18 | 19 | .nbs-flexisel-container { 20 | position:relative; 21 | max-width:100%; 22 | } 23 | .nbs-flexisel-ul { 24 | position:relative; 25 | width:99999px; 26 | margin:0px; 27 | padding:0px; 28 | list-style-type:none; 29 | text-align:center; 30 | overflow: auto; 31 | } 32 | 33 | .nbs-flexisel-inner { 34 | position: relative; 35 | overflow: hidden; 36 | float:left; 37 | width:100%; 38 | background:#fcfcfc; 39 | background: #fcfcfc -moz-linear-gradient(top, #fcfcfc 0%, #eee 100%); /* FF3.6+ */ 40 | background: #fcfcfc -webkit-gradient(linear, left top, left bottom, color-stop(0%,#fcfcfc), color-stop(100%,#eee)); /* Chrome,Safari4+ */ 41 | background: #fcfcfc -webkit-linear-gradient(top, #fcfcfc 0%, #eee 100%); /* Chrome10+,Safari5.1+ */ 42 | background: #fcfcfc -o-linear-gradient(top, #fcfcfc 0%, #eee 100%); /* Opera11.10+ */ 43 | background: #fcfcfc -ms-linear-gradient(top, #fcfcfc 0%, #eee 100%); /* IE10+ */ 44 | background: #fcfcfc linear-gradient(top, #fcfcfc 0%, #eee 100%); /* W3C */ 45 | border:1px solid #ccc; 46 | border-radius:5px; 47 | -moz-border-radius:5px; 48 | -webkit-border-radius:5px; 49 | } 50 | 51 | .nbs-flexisel-item { 52 | float:left; 53 | margin:0px; 54 | padding:0px; 55 | cursor:pointer; 56 | position:relative; 57 | line-height:0px; 58 | } 59 | .nbs-flexisel-item img { 60 | max-width: 100%; 61 | cursor: pointer; 62 | position: relative; 63 | margin-top: 10px; 64 | margin-bottom: 10px; 65 | } 66 | 67 | /*** Navigation ***/ 68 | 69 | .nbs-flexisel-nav-left, 70 | .nbs-flexisel-nav-right { 71 | padding:5px 10px; 72 | border-radius:15px; 73 | -moz-border-radius:15px; 74 | -webkit-border-radius:15px; 75 | position: absolute; 76 | cursor: pointer; 77 | z-index: 4; 78 | top: 50%; 79 | transform: translateY(-50%); 80 | background: rgba(0,0,0,0.5); 81 | color: #fff; 82 | } 83 | 84 | .nbs-flexisel-nav-left { 85 | left: 10px; 86 | } 87 | 88 | .nbs-flexisel-nav-left:before { 89 | content: "<" 90 | } 91 | 92 | .nbs-flexisel-nav-left.disabled { 93 | opacity: 0.4; 94 | } 95 | 96 | .nbs-flexisel-nav-right { 97 | right: 5px; 98 | } 99 | 100 | .nbs-flexisel-nav-right:before { 101 | content: ">" 102 | } 103 | 104 | .nbs-flexisel-nav-right.disabled { 105 | opacity: 0.4; 106 | } -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Flexisel - A responsive jQuery Carousel 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |

Flexisel

17 | 18 |

Flexisel will adapt responsively as the screen width gets smaller...

19 | 20 | 27 | 28 |
29 | 30 |

You can also change the number of items shown depending on the screen width.

31 | 32 | 39 | 40 |
41 | 42 |

Other options include autoplay, number of items to scroll, animation speed when scrolling right and left, initial number of visible items, and more!

43 | 44 | 50 | 51 |
52 | 53 |

And you can set whether you want the slider to be infinite or not.

54 | 55 | 63 | 64 | 127 | 128 | 129 | 130 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Flexisel 2 | ======== 3 | 4 | A responsive carousel jQuery plugin... 5 | 6 | [View Demo](http://9bitstudios.github.io/flexisel/) | [Buy Author a Coffee](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=NNCJ79B2W6MUL) 7 | 8 | All you have to do is call flexisel on your unordered list containing images. Call it on the 9 | 10 | ```javascript 11 | $(window).load 12 | ``` 13 | event (as opposed to the 14 | 15 | ```javascript 16 | $(document).ready 17 | ``` 18 | 19 | event so that Flexisel can calculate the width of the images and figure out how to space them out properly. For example... 20 | 21 | ```javascript 22 | $(window).load(function() { 23 | $("#myCarousel").flexisel(); 24 | }); 25 | ``` 26 | 27 | Below is how you'd call it passing in all the options.... 28 | 29 | ```javascript 30 | $(window).load(function() { 31 | $("#myCarousel").flexisel({ 32 | visibleItems: 4, 33 | itemsToScroll: 3, 34 | animationSpeed: 400, 35 | infinite: true, 36 | navigationTargetSelector: null, 37 | autoPlay: { 38 | enable: false, 39 | interval: 5000, 40 | pauseOnHover: true 41 | }, 42 | responsiveBreakpoints: { 43 | portrait: { 44 | changePoint:480, 45 | visibleItems: 1, 46 | itemsToScroll: 1 47 | }, 48 | landscape: { 49 | changePoint:640, 50 | visibleItems: 2, 51 | itemsToScroll: 2 52 | }, 53 | tablet: { 54 | changePoint:768, 55 | visibleItems: 3, 56 | itemsToScroll: 3 57 | } 58 | } 59 | }); 60 | }); 61 | ``` 62 | 63 | ### Options 64 | 65 | Below is a listing of some basic options you can set... 66 | 67 | | Option | Value | Default Value | Description | Example | 68 | | --- | --- | --- | --- | --- | 69 | visibleItems | Integer | 4 | Sets the initial number of visible items in the carousel | visibleItems: 5 70 | itemsToScroll | Integer | 3 | Sets the initial number of items that you want to scroll. Note: This value will be overridden by responsive breakpoint settings at smaller or larger screen widths | itemsToScroll: 2 71 | animationSpeed | Integer (in Milliseconds) | 400 | Sets the "speed" of the animation when the carousel navigates right or left. | animationSpeed: 1000 72 | infinite | Boolean | true | Sets whether or not the carousel wraps infinitely | infinite: false 73 | navigationTargetSelector | String (selector) | null | The left/right arrows will be added to the element with this selector instead of the default | navigationTargetSelector: '#navigation' 74 | autoPlay | Object | autoPlay: { enable: false, interval: 5000, pauseOnHover: true } | Values for setting autoplay. The "enable" property must be true for this to apply | autoPlay: { enable: true, interval: 7000, pauseOnHover: false } 75 | loaded | function | function(object) { } | Callback function that runs after the slider is loaded and initialized. A jQuery reference to the instance of the carousel is passed in as the first argument. | loaded: function(object) { console.log('Slider loaded...'); } 76 | before | function | function(object) { } | Callback function that runs before a slide transition. A jQuery reference to the instance of the carousel is passed in as the first argument. | before: function(object) { console.log('Before transition...'); } 77 | after | function | function(object) { } | Callback function that runs after a slide transition. A jQuery reference to the instance of the carousel is passed in as the first argument. | after: function(object) { console.log('After transition...'); } 78 | resize | function | function(object) { } | Callback function that runs after a throttled resize event finishes. A jQuery reference to the instance of the carousel is passed in as the first argument. | resize: function(object) { console.log('After resize...'); } 79 | 80 | 81 | ### Responsive Breakpoints 82 | 83 | This is an object that specifies responsive breakpoints. You can name your objects whatever you want (the default names provided are "portrait," "landscape," and "tablet") and you can have as many or as few as you want (so you could add to or delete any of the defaults), but each one needs to have a "changePoint" a "visibleItems", and an "itemsToScroll" property. Those properties are required. The responsiveBreakpoints object sets the threshold of where the screen width falls below a certain width. So for example, the example default portrait responsive breakpoint will be applied to the carousel when the screen width is less than the changePoint value set for portrait. The number of items shown in this state will be whatever value is set for visibleItems and the number of items that scroll per click (or swipe) is set by the itemsToScroll property. 84 | 85 | For example... 86 | 87 | ```javascript 88 | responsiveBreakpoints: { 89 | portrait: { 90 | changePoint:480, 91 | visibleItems: 1, 92 | itemsToScroll: 1 93 | }, 94 | landscape: { 95 | changePoint:640, 96 | visibleItems: 2, 97 | itemsToScroll: 2 98 | }, 99 | tablet: { 100 | changePoint:768, 101 | visibleItems: 3, 102 | itemsToScroll: 3 103 | } 104 | } 105 | ``` 106 | 107 | The landscape responsive breakpoint will be applied when the screen width is greater than the width of the portrait changePoint value, but less that the width of the tablet changePoint value. Likewise, when the screen width falls below the tablet changePoint, the number of visibleItems set for the tablet event will be shown. The same is true for the portrait breakpoint. Usually, because the portrait responsive event is used to show portrait views on mobile phones, 1 is a good value to set for both visibleItems and itemsToScroll here. And remember you can pass as many or as few of these as you like in and you can name them whatever you want. So, for example, if you wanted to just have things only show 1 item on all views below a certain width you could pass in something like the following... 108 | 109 | ```javascript 110 | responsiveBreakpoints: { 111 | mobile: { 112 | changePoint:768, 113 | visibleItems: 1, 114 | itemsToScroll: 1 115 | } 116 | } 117 | ``` 118 | 119 | And then this will be the only point at which Flexisel changes. 120 | 121 | [View Demo](http://9bitstudios.github.com/flexisel/) | [Buy Author a Coffee](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=NNCJ79B2W6MUL) 122 | -------------------------------------------------------------------------------- /js/jquery.flexisel.js: -------------------------------------------------------------------------------- 1 | /* 2 | * File: jquery.flexisel.js 3 | * Version: 2.2.2 4 | * Description: Responsive carousel jQuery plugin 5 | * Author: 9bit Studios 6 | * Copyright 2016, 9bit Studios 7 | * http://www.9bitstudios.com 8 | * Free to use and abuse under the MIT license. 9 | * http://www.opensource.org/licenses/mit-license.php 10 | */ 11 | 12 | (function ($) { 13 | 14 | $.fn.flexisel = function (options) { 15 | 16 | var defaults = $.extend({ 17 | visibleItems: 4, 18 | itemsToScroll: 3, 19 | animationSpeed: 400, 20 | infinite: true, 21 | navigationTargetSelector: null, 22 | autoPlay: { 23 | enable: false, 24 | interval: 5000, 25 | pauseOnHover: true 26 | }, 27 | responsiveBreakpoints: { 28 | portrait: { 29 | changePoint:480, 30 | visibleItems: 1, 31 | itemsToScroll: 1 32 | }, 33 | landscape: { 34 | changePoint:640, 35 | visibleItems: 2, 36 | itemsToScroll: 2 37 | }, 38 | tablet: { 39 | changePoint:768, 40 | visibleItems: 3, 41 | itemsToScroll: 3 42 | } 43 | }, 44 | loaded: function(){ }, 45 | before: function(){ }, 46 | after: function(){ }, 47 | resize: function(){ } 48 | }, options); 49 | 50 | /****************************** 51 | Private Variables 52 | *******************************/ 53 | 54 | var object = $(this); 55 | var settings = $.extend(defaults, options); 56 | var itemsWidth; 57 | var canNavigate = true; 58 | var itemCount; 59 | var itemsVisible = settings.visibleItems; 60 | var itemsToScroll = settings.itemsToScroll; 61 | var responsivePoints = []; 62 | var resizeTimeout; 63 | var autoPlayInterval; 64 | 65 | /****************************** 66 | Public Methods 67 | *******************************/ 68 | 69 | var methods = { 70 | 71 | init: function() { 72 | return this.each(function () { 73 | methods.appendHTML(); 74 | methods.setEventHandlers(); 75 | methods.initializeItems(); 76 | }); 77 | }, 78 | 79 | /****************************** 80 | Initialize Items 81 | *******************************/ 82 | 83 | initializeItems: function() { 84 | 85 | var obj = settings.responsiveBreakpoints; 86 | for(var i in obj) { responsivePoints.push(obj[i]); } 87 | responsivePoints.sort(function(a, b) { return a.changePoint - b.changePoint; }); 88 | var childSet = object.children(); 89 | childSet.first().addClass("index"); 90 | itemsWidth = methods.getCurrentItemWidth(); 91 | itemCount = childSet.length; 92 | childSet.width(itemsWidth); 93 | if(settings.infinite) { 94 | methods.offsetItemsToBeginning(Math.floor(childSet.length / 2)); 95 | object.css({ 96 | 'left': -itemsWidth * Math.floor(childSet.length / 2) 97 | }); 98 | } 99 | $(window).trigger('resize'); 100 | object.fadeIn(); 101 | settings.loaded.call(this, object); 102 | 103 | }, 104 | 105 | /****************************** 106 | Append HTML 107 | *******************************/ 108 | 109 | appendHTML: function() { 110 | 111 | object.addClass("nbs-flexisel-ul"); 112 | object.wrap("
"); 113 | object.find("li").addClass("nbs-flexisel-item"); 114 | 115 | if(settings.navigationTargetSelector && $(settings.navigationTargetSelector).length > 0) { 116 | $("
").appendTo(settings.navigationTargetSelector); 117 | } else { 118 | settings.navigationTargetSelector = object.parent(); 119 | $("
").insertAfter(object); 120 | } 121 | 122 | if(settings.infinite) { 123 | var childSet = object.children(); 124 | var cloneContentBefore = childSet.clone(); 125 | var cloneContentAfter = childSet.clone(); 126 | object.prepend(cloneContentBefore); 127 | object.append(cloneContentAfter); 128 | } 129 | 130 | }, 131 | 132 | 133 | /****************************** 134 | Set Event Handlers 135 | *******************************/ 136 | setEventHandlers: function() { 137 | var self = this; 138 | var childSet = object.children(); 139 | 140 | $(window).on("resize", function(event){ 141 | canNavigate = false; 142 | clearTimeout(resizeTimeout); 143 | resizeTimeout = setTimeout(function(){ 144 | canNavigate = true; 145 | methods.calculateDisplay(); 146 | itemsWidth = methods.getCurrentItemWidth(); 147 | childSet.width(itemsWidth); 148 | 149 | if(settings.infinite) { 150 | object.css({ 151 | 'left': -itemsWidth * Math.floor(childSet.length / 2) 152 | }); 153 | } else { 154 | methods.clearDisabled(); 155 | $(settings.navigationTargetSelector).find(".nbs-flexisel-nav-left").addClass('disabled'); 156 | object.css({ 157 | 'left': 0 158 | }); 159 | } 160 | 161 | settings.resize.call(self, object); 162 | 163 | }, 100); 164 | 165 | }); 166 | 167 | $(settings.navigationTargetSelector).find(".nbs-flexisel-nav-left").on("click", function (event) { 168 | methods.scroll(true); 169 | }); 170 | 171 | $(settings.navigationTargetSelector).find(".nbs-flexisel-nav-right").on("click", function (event) { 172 | methods.scroll(false); 173 | }); 174 | 175 | if(settings.autoPlay.enable) { 176 | 177 | methods.setAutoplayInterval(); 178 | 179 | if (settings.autoPlay.pauseOnHover === true) { 180 | object.on({ 181 | mouseenter : function() { 182 | canNavigate = false; 183 | }, 184 | mouseleave : function() { 185 | canNavigate = true; 186 | } 187 | }); 188 | } 189 | 190 | } 191 | 192 | object[0].addEventListener('touchstart', methods.touchHandler.handleTouchStart, false); 193 | object[0].addEventListener('touchmove', methods.touchHandler.handleTouchMove, false); 194 | 195 | }, 196 | 197 | /****************************** 198 | Calculate Display 199 | *******************************/ 200 | 201 | calculateDisplay: function() { 202 | var contentWidth = $('html').width(); 203 | var largestCustom = responsivePoints[responsivePoints.length-1].changePoint; // sorted array 204 | 205 | for(var i in responsivePoints) { 206 | 207 | if(contentWidth >= largestCustom) { // set to default if width greater than largest custom responsiveBreakpoint 208 | itemsVisible = settings.visibleItems; 209 | itemsToScroll = settings.itemsToScroll; 210 | break; 211 | } 212 | else { // determine custom responsiveBreakpoint to use 213 | 214 | if(contentWidth < responsivePoints[i].changePoint) { 215 | itemsVisible = responsivePoints[i].visibleItems; 216 | itemsToScroll = responsivePoints[i].itemsToScroll; 217 | break; 218 | } 219 | else { 220 | continue; 221 | } 222 | } 223 | } 224 | 225 | }, 226 | 227 | /****************************** 228 | Scroll 229 | *******************************/ 230 | 231 | scroll: function(reverse) { 232 | 233 | if(typeof reverse === 'undefined') { reverse = true } 234 | 235 | if(canNavigate == true) { 236 | canNavigate = false; 237 | settings.before.call(this, object); 238 | itemsWidth = methods.getCurrentItemWidth(); 239 | 240 | if(settings.autoPlay.enable) { 241 | clearInterval(autoPlayInterval); 242 | } 243 | 244 | if(!settings.infinite) { 245 | 246 | var scrollDistance = itemsWidth * itemsToScroll; 247 | 248 | if(reverse) { 249 | object.animate({ 250 | 'left': methods.calculateNonInfiniteLeftScroll(scrollDistance) 251 | }, settings.animationSpeed, function(){ 252 | settings.after.call(this, object); 253 | canNavigate = true; 254 | }); 255 | 256 | } else { 257 | object.animate({ 258 | 'left': methods.calculateNonInfiniteRightScroll(scrollDistance) 259 | },settings.animationSpeed, function(){ 260 | settings.after.call(this, object); 261 | canNavigate = true; 262 | }); 263 | } 264 | 265 | 266 | 267 | } else { 268 | object.animate({ 269 | 'left' : reverse ? "+=" + itemsWidth * itemsToScroll : "-=" + itemsWidth * itemsToScroll 270 | }, settings.animationSpeed, function() { 271 | settings.after.call(this, object); 272 | canNavigate = true; 273 | 274 | if(reverse) { 275 | methods.offsetItemsToBeginning(itemsToScroll); 276 | } else { 277 | methods.offsetItemsToEnd(itemsToScroll); 278 | } 279 | methods.offsetSliderPosition(reverse); 280 | 281 | }); 282 | } 283 | 284 | if(settings.autoPlay.enable) { 285 | methods.setAutoplayInterval(); 286 | } 287 | 288 | } 289 | }, 290 | 291 | touchHandler: { 292 | 293 | xDown: null, 294 | yDown: null, 295 | handleTouchStart: function(evt) { 296 | this.xDown = evt.touches[0].clientX; 297 | this.yDown = evt.touches[0].clientY; 298 | }, 299 | handleTouchMove: function (evt) { 300 | if (!this.xDown || !this.yDown) { 301 | return; 302 | } 303 | 304 | var xUp = evt.touches[0].clientX; 305 | var yUp = evt.touches[0].clientY; 306 | 307 | var xDiff = this.xDown - xUp; 308 | var yDiff = this.yDown - yUp; 309 | 310 | // only comparing xDiff 311 | // compare which is greater against yDiff to determine whether left/right or up/down e.g. if (Math.abs( xDiff ) > Math.abs( yDiff )) 312 | if (Math.abs( xDiff ) > 0) { 313 | if ( xDiff > 0 ) { 314 | // swipe left 315 | methods.scroll(false); 316 | } else { 317 | //swipe right 318 | methods.scroll(true); 319 | } 320 | } 321 | 322 | /* reset values */ 323 | this.xDown = null; 324 | this.yDown = null; 325 | canNavigate = true; 326 | } 327 | }, 328 | 329 | /****************************** 330 | Utility Functions 331 | *******************************/ 332 | 333 | getCurrentItemWidth: function() { 334 | return (object.parent().width())/itemsVisible; 335 | }, 336 | 337 | offsetItemsToBeginning: function(number) { 338 | if(typeof number === 'undefined') { number = 1 } 339 | for(var i = 0; i < number; i++) { 340 | object.children().last().insertBefore(object.children().first()); 341 | } 342 | }, 343 | 344 | offsetItemsToEnd: function(number) { 345 | if(typeof number === 'undefined') { number = 1 } 346 | for(var i = 0; i < number; i++) { 347 | object.children().first().insertAfter(object.children().last()); 348 | } 349 | }, 350 | 351 | offsetSliderPosition: function(reverse) { 352 | var left = parseInt(object.css('left').replace('px', '')); 353 | if (reverse) { 354 | left = left - itemsWidth * itemsToScroll; 355 | } else { 356 | left = left + itemsWidth * itemsToScroll; 357 | } 358 | object.css({ 359 | 'left': left 360 | }); 361 | }, 362 | 363 | getOffsetPosition: function() { 364 | return parseInt(object.css('left').replace('px', '')); 365 | }, 366 | 367 | calculateNonInfiniteLeftScroll: function(toScroll) { 368 | 369 | methods.clearDisabled(); 370 | if(methods.getOffsetPosition() + toScroll >= 0) { 371 | $(settings.navigationTargetSelector).find(".nbs-flexisel-nav-left").addClass('disabled'); 372 | return 0; 373 | } else { 374 | return methods.getOffsetPosition() + toScroll; 375 | } 376 | }, 377 | 378 | calculateNonInfiniteRightScroll: function(toScroll){ 379 | 380 | methods.clearDisabled(); 381 | var negativeOffsetLimit = (itemCount * itemsWidth) - (itemsVisible * itemsWidth); 382 | 383 | if(methods.getOffsetPosition() - toScroll <= -negativeOffsetLimit) { 384 | $(settings.navigationTargetSelector).find(".nbs-flexisel-nav-right").addClass('disabled'); 385 | return -negativeOffsetLimit; 386 | } else { 387 | return methods.getOffsetPosition() - toScroll; 388 | } 389 | }, 390 | 391 | setAutoplayInterval: function(){ 392 | autoPlayInterval = setInterval(function() { 393 | if (canNavigate) { 394 | methods.scroll(false); 395 | } 396 | }, settings.autoPlay.interval); 397 | }, 398 | 399 | clearDisabled: function() { 400 | var parent = $(settings.navigationTargetSelector); 401 | parent.find(".nbs-flexisel-nav-left").removeClass('disabled'); 402 | parent.find(".nbs-flexisel-nav-right").removeClass('disabled'); 403 | } 404 | 405 | }; 406 | 407 | if (methods[options]) { // $("#element").pluginName('methodName', 'arg1', 'arg2'); 408 | return methods[options].apply(this, Array.prototype.slice.call(arguments, 1)); 409 | } else if (typeof options === 'object' || !options) { // $("#element").pluginName({ option: 1, option:2 }); 410 | return methods.init.apply(this); 411 | } else { 412 | $.error( 'Method "' + method + '" does not exist in flexisel plugin!'); 413 | } 414 | }; 415 | 416 | })(jQuery); 417 | --------------------------------------------------------------------------------