iosslider is a jQuery plugin which allows you to integrate a customizable, cross-browser content slider into your web presence. Designed for use as a content slider, carousel, scrolling website banner, or image gallery.
Browser | Version |
---|---|
Safari | 4.0+ |
Chrome | 19.0+ |
Browser | Version |
---|---|
Internet Explorer | 10+ |
Browser | Version |
---|---|
Firefox | 5.0+ |
Chrome | 19.0+ |
Safari | 5.0+ |
Internet Explorer | 7+ |
Browser | Version |
---|---|
Stock | 2.3+ |
Firefox | 18.0+ |
Chrome | 19.0+ |
Opera | 12.0+ |
iosslider may work in earlier versions of browsers listed, but are not supported at this time.
To get started, you will need to download the iosslider script. The download package contains the iosslider script, the jQuery library, demos and benchmarks.
The jQuery library and iosslider Plugin scripts must be included in the HTML header of the web page. The jQuery library must be included first for the iosslider plugin to function.
<!-- jQuery library --> <script type = 'text/javascript' src = 'jquery-1.4.min.js'></script> <!-- iosslider plugin --> <script type = 'text/javascript' src = 'jquery.iosslider.js'></script>
Add the iosslider HTML code within the body of the web page. The HTML can contain as little as one slide element.
<div class = 'iosslider'> <!-- slider --> <div class = 'slider'> <!-- slides --> <div class = 'slide'>...</div> <div class = 'slide'>...</div> <div class = 'slide'>...</div> </div> </div>
Place the CSS in your stylesheet. The required CSS attributes are included to guarantee optimal performance. Feel free to apply as many other CSS attributes as you want. To see some real-world examples of this, check the demos folder of the iosslider download package.
/* slider container */ .iosSlider { /* required */ position: relative; top: 0; left: 0; overflow: hidden; width:px; height: px; } /* slider */ .iosSlider .slider { /* required */ width: 100%; height: 100%; } /* slide */ .iosSlider .slider .slide { /* required */ float: left; width: px; height: px; }
Add the code below to your JavaScript file. The following code uses the jQuery selector to initialize the iosslider jQuery plugin. If you are unfamiliar with jQuery, here is a tutorial to get you started.
$(document).ready(function() { /* basic - default settings */ $('.iosSlider').iosSlider(); /* some custom settings */ $('.iosSlider').iosSlider({ snapToChildren: true, scrollbar: true, scrollbarHide: false, desktopClickDrag: true, scrollbarLocation: 'bottom', scrollbarHeight: '6px', scrollbarBackground: 'url(_img/some-img.png) repeat 0 0', scrollbarBorder: '1px solid #000', scrollbarMargin: '0 30px 16px 30px', scrollbarOpacity: '0.75', onSlideChange: changeSlideIdentifier }); });
You can pass along any of the following key/value pairs listed below to the iosSlider() function or modify them within the iosslider JavaScript file directly.
Key | Value | Description |
---|---|---|
elasticPullResistance | 0.6 | (decimal, 0.0 - 1.0) The elastic resistance when pulling on the slider edge. |
frictionCoefficient | 0.92 | (decimal, 0.0 - 1.0) The friction coefficient applied to the momentum on touch release affecting the rate of deceleration. |
elasticFrictionCoefficient | 0.6 | (decimal, 0.0 - 1.0) Additonal friction coefficient applied when momentum slides outside the bounds of the slider. |
snapFrictionCoefficient | 0.92 | (decimal, 0.0 - 1.0) Friction applied to the slider when snapping to an element. |
snapToChildren | false | (boolean) Slider will slide to the closest child element on touch release. |
snapSlideCenter | false | (boolean) When snapToChildren is true, this option will snap the slide to the center of the draggable area. |
startAtSlide | 1 | (integer) Current slide when slider is initially loaded. |
scrollbar | false | (boolean) Show or hide the scrollbar. |
scrollbarDrag | false | (boolean) Enables click/drag, touch/drag functionality on the scrollbar. When enabled, the options scrollbar and scrollbarHide are automatically set to true and false respectively. |
scrollbarHide | true | (boolean) Show or hide the scrollbar when it is idle. |
scrollbarLocation | 'top' | (string, 'bottom' or 'top') Location that the scrollbar will appear. |
scrollbarContainer | '' | (string) A jQuery selection (ex. $('#scrollbarContainer') ), the scrollbar will be loaded and contained by this selection. The scrollbar width will be defined by this container. |
scrollbarOpacity | 0.4 | (decimal) The css opacity of the scrollbar when visible. |
scrollbarHeight | '4px' | (string) The css height in 'px' of the scrollbar. |
scrollbarBorder | 'none' | (string) The css border of the scrollbar. |
scrollbarMargin | '5px' | (string) The css margin of the scrollbar. |
scrollbarBackground | 'none' | (string) The css background of the scrollbar. |
scrollbarBorderRadius | '100px' | (string) The css border-radius of the scrollbar. |
scrollbarShadow | 'none' | (string) The css box-shadow of the scrollbar. |
scrollbarElasticPullResistance | 0.9 | (decimal, 0.0 - 1.0) Additonal friction coefficient applied to the scrollbar when momentum/user moves slides outside the bounds of the slider. |
desktopClickDrag | false | (boolean) Desktop click and drag fallback for the desktop slider. |
keyboardControls | false | (boolean) Left/right keyboard arrows can be used to navigate the slider. |
tabToAdvance | false | (boolean) Tab key can be used to navigate the slider forward. |
responsiveSlideContainer | true | (boolean) Width of slide container becomes responsive to the width/height of its parent element. Slide container dynamically collapse to the width/height of the parent element when wider/taller. |
responsiveSlides | true | (boolean) Width of slides becomes responsive to the width/height of its parent element. Slides dynamically collapse to the width/height of the parent element of the slider when wider/taller. |
navSlideSelector | null | (string) A jQuery selection (ex. $('.navButtons .button') ), each element returned by the selector will activate navigation to each slide respectively. ie. element 0 when clicked (or touched) will animate to the first slide and so on. |
navPrevSelector | null | (string) A jQuery selection (ex. $('#previousSlide') ), the element returned by the selector will navigate to the previous slide when clicked. |
navNextSelector | null | (string) A jQuery selection (ex. $('#nextSlide') ), the element returned by the selector will navigate to the next slide when clicked. |
autoSlide | false | (boolean) Enables automatic cycling through slides. |
autoSlideTimer | 5000 | (integer) the time (in milliseconds) that a slide will wait before automatically navigating to the next slide. |
autoSlideTransTimer | 750 | (integer) the time (in milliseconds) required for all automatic animations to move between slides. See navSlideSelector, navPrevSelector, navNextSelector for details on activating elements for automatic sliding. |
autoSlideToggleSelector | null | (string) A jQuery selection (ex. $('#autoScrollToggle') ), the element returned by the selector will disable/enable automatic scrolling when clicked. Note: Only works when autoSlide is set to 'true'. |
autoSlideHoverPause | true | (boolean) Enables pausing of the autoSlide function when the user mouses over the slider area. |
infiniteSlider | false | (boolean) Makes the slider loop in both directions infinitely with no end. When set to true, the option scrollbar is automatically disabled. |
snapVelocityThreshold | 5 | Minimum slide velocity threshold required to trigger slide snapping to next/previous slide. |
slideStartVelocityThreshold | 0 | Minimum slide velocity threshold required to begin slider movement. |
horizontalSlideLockThreshold | 5 | Minimum slide velocity threshold required to lock vertical sliding in the browser. |
verticalSlideLockThreshold | 3 | Minimum slide velocity threshold required to lock horizontal slider movement. |
stageCSS | { position: 'relative', top: '0', left: '0', overflow: 'hidden', zIndex: 1 } | (object) The customizable CSS of the stage object. |
sliderCSS | { overflow: 'hidden' } | (object) The customizable CSS of the slider object. |
unselectableSelector | null | (string) A jQuery selection (ex. $('.unselectable') ), each element returned by the selector will become removed from touch/click move events. |
Advanced callbacks allow further customization through end user created functions/hooks. For additional information regarding parameters supplied to these callbacks, see parameter object details directly below the following table.
Key | Value | Description |
---|---|---|
onSliderLoaded | null | (function) Executed when slider has finished loading initially. |
onSliderUpdate | null | (function) Executed when public method 'update' has been completed. |
onSliderResize | null | (function) Executed when the window has been resized or a device has been rotated. |
onSlideStart | null | (function) Executed when the slider has begun to move. |
onSlideChange | null | (function) Executed when the slider has entered the range of a new slide. |
onSlideComplete | null | (function) Executed when the slider has come to a stop on a new slide. |
All callback functions listed above return the same object, for our example, we will call this object 'args'.
args = { settings: { /* all basic/advanced settings & options from above */ }, data: { obj, settings, scrollerNode, numberOfSlides, sliderNumber, childrenOffsets, sliderMax, scrollbarClass, scrollbarWidth, scrollbarStageWidth, stageWidth, scrollMargin, scrollBorder, infiniteSliderOffset, infiniteSliderWidth }, sliderObject, sliderContainerObject, targetSlideObject, targetSlideNumber, currentSlideObject, currentSlideNumber, currentSliderOffset }
Accessing callback parameter data following the above object structure.
$('.iosSlider').iosSlider({ onSlideChange: someCallback }); function someCallback(args) { /* accessing user defined settings from initialization */ var autoSlideToggleSelector = args.settings.autoSlideToggleSelector; /* accessing data from the slider object */ var sliderMax = args.data.sliderMax; /* additional calculated variables supplied to the 'args' object */ var currentSlideNumber = args.currentSlideNumber; }
Additional public information is stored using the jQuery.data() object. For usage and access instructions, please consult the jQuery.data() object reference.
/* General variables. These variables are set during initialization, * window resize, orientation change, and via the 'update' public method */ $('.iosSlider').data('iosslider', { obj, settings, scrollerNode, numberOfSlides, sliderNumber, childrenOffsets, sliderMax, scrollbarClass, scrollbarWidth, scrollbarStageWidth, stageWidth, scrollMargin, scrollBorder, infiniteSliderOffset, infiniteSliderWidth }); /* Dynamic variables. These variables are updated with every user interaction. */ $('.iosSlider').data('args', { sliderObject, sliderContainerObject, slideChanged, prevSlideNumber, prevSliderOffset targetSlideObject, targetSlideNumber, currentSlideObject, currentSlideNumber, currentSliderOffset });
Method | Description |
---|---|
$(element).iosSlider('destroy'); | Destroys the selected slider. Optional parameter: 'clearStyle' (boolean, default: true) when iosslider is destroyed, all inline style applied to the slider will be removed. |
$(element).iosSlider('goToSlide', slideNum); | Moves to the selected slide. Required parameter: 'slideNumber' (integer, default: null) |
$(element).iosSlider('prevSlide', slideNum); | Slides to the previous slide. |
$(element).iosSlider('nextSlide', slideNum); | Slides to the next slide. |
$(element).iosSlider('update'); | Updates/reinitializes internal variables/CSS attributes based on changes to the HTML/CSS/JS structure of the slider. |
$(element).iosSlider('addSlide', slideHTML, slidePosition); | Adds a slide defined by 'slideHTML' and placed at position 'slidePosition'. Required parameters: 'slideHTML' (string, default: null), 'slidePosition' (integer, default: null) |
$(element).iosSlider('removeSlide', slideNum); | Removes a slide from the slider. Required parameter: 'slideNumber' (integer, default: null) |
$(element).iosSlider('lock'); | Locks the slider. Temporarily disabling touch/drag events within the slider without unbinding them. |
$(element).iosSlider('unlock'); | Unlocks the slider. Enables touch/drag events previously disabled by the lock method. |
$(element).iosSlider('autoSlidePlay'); | Starts and enables auto-sliding on the slider. |
$(element).iosSlider('autoSlidePause'); | Stops the slider from auto-sliding. |
Licensing options can be found at http://iosscripts.com/iosslider/#licensing
Need help setting up one of our plugins? Drop us a line and we'll do our best to help.
If you have an idea for a new feature or if our plugins are missing something your application needs, tell us about it and we'll consider adding it!
If you think you might have found a bug in one of our plugins, let us know. We'll take a look under the hood and see if we can fix it.