Ejemplo jQuery: slider de imágenes

logo jQuery

Ejemplo de código fuente con jQuery, para poner un slider o rotador/carrusel de imágenes a nuestra página HTML, mediante un plugin llamado jQuery FlexSlider, muy útil a veces para aumentar la facilidad de uso de nuestro sitio web o para atraer a más usuarios.



Configuración de FlexSlider

FlexSlider tiene diversas opciones para configurar el slide a nuestro gusto:

namespace: "flex-",             //String: Prefix string attached to the class of every element generated by the plugin
selector: ".slides > li",       //Selector: Must match a simple pattern. '{container} > {slide}' -- Ignore pattern at your own peril
animation: "fade",              //String: Select your animation type, "fade" or "slide"
easing: "swing",                //String: Determines the easing method used in jQuery transitions. jQuery easing plugin is supported!
direction: "horizontal",        //String: Select the sliding direction, "horizontal" or "vertical"
reverse: false,                 //Boolean: Reverse the animation direction
animationLoop: true,            //Boolean: Should the animation loop? If false, directionNav will received "disable" classes at either end
smoothHeight: false,            //Boolean: Allow height of the slider to animate smoothly in horizontal mode  
startAt: 0,                     //Integer: The slide that the slider should start on. Array notation (0 = first slide)
slideshow: true,                //Boolean: Animate slider automatically
slideshowSpeed: 7000,           //Integer: Set the speed of the slideshow cycling, in milliseconds
animationSpeed: 600,            //Integer: Set the speed of animations, in milliseconds
initDelay: 0,                   //Integer: Set an initialization delay, in milliseconds
randomize: false,               //Boolean: Randomize slide order

// Usability features
pauseOnAction: true,            //Boolean: Pause the slideshow when interacting with control elements, highly recommended.
pauseOnHover: false,            //Boolean: Pause the slideshow when hovering over slider, then resume when no longer hovering
useCSS: true,                   //Boolean: Slider will use CSS3 transitions if available
touch: true,                    //Boolean: Allow touch swipe navigation of the slider on touch-enabled devices
video: false,                   //Boolean: If using video in the slider, will prevent CSS3 3D Transforms to avoid graphical glitches

// Primary Controls
controlNav: true,               //Boolean: Create navigation for paging control of each clide? Note: Leave true for manualControls usage
directionNav: true,             //Boolean: Create navigation for previous/next navigation? (true/false)
prevText: "Previous",           //String: Set the text for the "previous" directionNav item
nextText: "Next",               //String: Set the text for the "next" directionNav item

// Secondary Navigation
keyboard: true,                 //Boolean: Allow slider navigating via keyboard left/right keys
multipleKeyboard: false,        //Boolean: Allow keyboard navigation to affect multiple sliders. Default behavior cuts out keyboard navigation with more than one slider present.
mousewheel: false,              //Boolean: Requires jquery.mousewheel.js (https://github.com/brandonaaron/jquery-mousewheel) - Allows slider navigating via mousewheel
pausePlay: false,               //Boolean: Create pause/play dynamic element
pauseText: 'Pause',             //String: Set the text for the "pause" pausePlay item
playText: 'Play',               //String: Set the text for the "play" pausePlay item

// Special properties
controlsContainer: "",          //Selector: USE CLASS SELECTOR. Declare which container the navigation elements should be appended too. Default container is the FlexSlider element. Example use would be ".flexslider-container". Property is ignored if given element is not found.
manualControls: "",             //Selector: Declare custom control navigation. Examples would be ".flex-control-nav li" or "#tabs-nav li img", etc. The number of elements in your controlNav should match the number of slides/tabs.
sync: "",                       //Selector: Mirror the actions performed on this slider with another slider. Use with care.
asNavFor: "",                   //Selector: Internal property exposed for turning the slider into a thumbnail navigation for another slider

// Carousel Options
itemWidth: 0,                   //Integer: Box-model width of individual carousel items, including horizontal borders and padding.
itemMargin: 0,                  //Integer: Margin between carousel items.
minItems: 0,                    //Integer: Minimum number of carousel items that should be visible. Items will resize fluidly when below this.
maxItems: 0,                    //Integer: Maxmimum number of carousel items that should be visible. Items will resize fluidly when above this limit.
move: 0,                        //Integer: Number of carousel items that should move on animation. If 0, slider will move all visible items.
// Callback API
start: function(){},            //Callback: function(slider) - Fires when the slider loads the first slide
before: function(){},           //Callback: function(slider) - Fires asynchronously with each slider animation
after: function(){},            //Callback: function(slider) - Fires after each slider animation completes
end: function(){},              //Callback: function(slider) - Fires when the slider reaches the last slide (asynchronous)
added: function(){},            //Callback: function(slider) - Fires after a slide is added
removed: function(){}           //Callback: function(slider) - Fires after a slide is removed



Código jQuery.

$(window).load(function() {
	animation: "slide",


Código HTML.

<!-- Contenido -->

<div class="flexslider">
  <ul class="slides">
	  <img src="imagenes/boat.jpg" />
	  <img src="imagenes/coast.jpg" />
	  <img src="imagenes/evening.jpg" />
	  <img src="imagenes/stones.jpg" />
	  <img src="imagenes/waves.jpg" />

<!-- jQuery -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

<!-- FlexSlider -->
<script defer src="jquery.flexslider-min.js"></script>


Otros plugins para realizar un slide

Existen otros plugins para realizar lo mismo que podemos hacer con FlexSlider o incluso con muchos más efectos. Yo destaco estos:


Demo del ejemplo



Descargar ejemplo



Valoración General

[Valoraciones:  1    Promedio:  5 de 5]