UPDATE: Please visit the new jFlow Plus article for the latest version's documentation, download and demo.
The following article is no longer supported:
Why jFlow is a Good Slider
jFlow is a very light-weight slider. If you've been using sliders in your web design for some time perhaps you've had experiences with a few jQuery sliders that hasn't been so good. jFlow out-of-the-box is good, but let's make it great. One of the most requested features for this slider is to have the popular pause and autoslide functions.
The jFlow Plug-In
Here's a look at the jFlow plug-in Version 1.2: Notice how there's no coding for an automatic slide feature.
/* Copyright (c) 2008 Kean Loong Tan http://www.gimiti.com/kltan
* Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
* jFlow
* Version: 1.0 (May 13, 2008)
* Requires: jQuery 1.2+
*/
(function($) {
$.fn.jFlow = function(options) {
var opts = $.extend({}, $.fn.jFlow.defaults, options);
var cur = 0;
var maxi = $(".jFlowControl").length;
$(this).find(".jFlowControl").each(function(i){
$(this).click(function(){
$(".jFlowControl").removeClass("jFlowSelected");
$(this).addClass("jFlowSelected");
var dur = Math.abs(cur-i+1);
$(opts.slides).animate({
marginLeft: "-" + (i * $(opts.slides).find(":first-child").width() + "px")
}, opts.duration*(dur));
cur = i;
});
});
$(opts.slides).before('<div id="jFlowSlide"></div>').appendTo("#jFlowSlide");
$(opts.slides).find("div").each(function(){
$(this).before('<div></div>').appendTo($(this).prev());
});
//initialize the controller
$(".jFlowControl").eq(cur).addClass("jFlowSelected");
var resize = function (x){
$("#jFlowSlide").css({
position:"relative",
width: opts.width,
height: opts.height,
overflow: "hidden"
});
$(opts.slides).css({
position:"relative",
width: $("#jFlowSlide").width()*$(".jFlowControl").length+"px",
height: $("#jFlowSlide").height()+"px",
overflow: "hidden"
});
$(opts.slides).children().css({
position:"relative",
width: $("#jFlowSlide").width()+"px",
height: $("#jFlowSlide").height()+"px",
"float":"left"
});
$(opts.slides).css({
marginLeft: "-" + (cur * $(opts.slides).find(":first-child").width() + "px")
});
}
resize();
$(window).resize(function(){
resize();
});
$(".jFlowPrev").click(function(){
if (cur > 0)
cur--;
else
cur = maxi -1;
$(".jFlowControl").removeClass("jFlowSelected");
$(opts.slides).animate({
marginLeft: "-" + (cur * $(opts.slides).find(":first-child").width() + "px")
}, opts.duration);
$(".jFlowControl").eq(cur).addClass("jFlowSelected");
});
$(".jFlowNext").click(function(){
if (cur < maxi - 1)
cur++;
else
cur = 0;
$(".jFlowControl").removeClass("jFlowSelected");
$(opts.slides).animate({
marginLeft: "-" + (cur * $(opts.slides).find(":first-child").width() + "px")
}, opts.duration);
$(".jFlowControl").eq(cur).addClass("jFlowSelected");
});
};
$.fn.jFlow.defaults = {
easing: "swing",
duration: 400,
width: "100%"
};
})(jQuery);
jFlow Demo
Recently I put up a demo on my other website wordimpressed.com, you can view it here: jFlow Slider Demo on WordImpressed. Also, be sure to read the newer article I wrote about the jFlow Plus Release.
jFlow Auto Slide
Have you been searching on Google for an easy Auto Slide solution for the jQuery jFlow plug-in? Well, look no more... you have found it. Here's the solution below. Expand to see the code or download it using the link below.
/* Copyright (c) 2008 Kean Loong Tan http://www.gimiti.com/kltan
* Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
* jFlow
* Version: 1.2 (July 7, 2008)
* Requires: jQuery 1.2+
*/
(function($) {
$.fn.jFlow = function(options) {
var opts = $.extend({}, $.fn.jFlow.defaults, options);
var randNum = Math.floor(Math.random()*11);
var jFC = opts.controller;
var jFS = opts.slideWrapper;
var jSel = opts.selectedWrapper;
var cur = 0;
var timer;
var maxi = $(jFC).length;
// sliding function
var slide = function (dur, i) {
$(opts.slides).children().css({
overflow:"hidden"
});
$(opts.slides + " iframe").hide().addClass("temp_hide");
$(opts.slides).animate({
marginLeft: "-" + (i * $(opts.slides).find(":first-child").width() + "px")
},
opts.duration*(dur),
opts.easing,
function(){
$(opts.slides).children().css({
overflow:"hidden"
});
$(".temp_hide").show();
}
);
}
$(this).find(jFC).each(function(i){
$(this).click(function(){
dotimer();
if ($(opts.slides).is(":not(:animated)")) {
$(jFC).removeClass(jSel);
$(this).addClass(jSel);
var dur = Math.abs(cur-i);
slide(dur,i);
cur = i;
}
});
});
$(opts.slides).before('<div id="'+jFS.substring(1, jFS.length)+'"></div>').appendTo(jFS);
$(opts.slides).find("div").each(function(){
$(this).before('<div></div>').appendTo($(this).prev());
});
//initialize the controller
$(jFC).eq(cur).addClass(jSel);
var resize = function (x){
$(jFS).css({
position:"relative",
width: opts.width,
height: opts.height,
overflow: "hidden"
});
//opts.slides or #mySlides container
$(opts.slides).css({
position:"relative",
width: $(jFS).width()*$(jFC).length+"px",
height: $(jFS).height()+"px",
overflow: "hidden"
});
// jFlowSlideContainer
$(opts.slides).children().css({
position:"relative",
width: $(jFS).width()+"px",
height: $(jFS).height()+"px",
"float":"left",
overflow:"hidden"
});
$(opts.slides).css({
marginLeft: "-" + (cur * $(opts.slides).find(":eq(0)").width() + "px")
});
}
// sets initial size
resize();
// resets size
$(window).resize(function(){
resize();
});
$(opts.prev).click(function(){
dotimer();
doprev();
});
$(opts.next).click(function(){
dotimer();
donext();
});
var doprev = function (x){
if ($(opts.slides).is(":not(:animated)")) {
var dur = 1;
if (cur > 0)
cur--;
else {
cur = maxi -1;
dur = cur;
}
$(jFC).removeClass(jSel);
slide(dur,cur);
$(jFC).eq(cur).addClass(jSel);
}
}
var donext = function (x){
if ($(opts.slides).is(":not(:animated)")) {
var dur = 1;
if (cur < maxi - 1)
cur++;
else {
cur = 0;
dur = maxi -1;
}
$(jFC).removeClass(jSel);
//$(jFS).fadeOut("fast");
slide(dur, cur);
//$(jFS).fadeIn("fast");
$(jFC).eq(cur).addClass(jSel);
}
}
var dotimer = function (x){
if((opts.auto) == true) {
if(timer != null)
clearInterval(timer);
timer = setInterval(function() {
$(opts.next).click();
}, 3000);
}
}
dotimer();
};
$.fn.jFlow.defaults = {
controller: ".jFlowControl", // must be class, use . sign
slideWrapper : "#jFlowSlide", // must be id, use # sign
selectedWrapper: "jFlowSelected", // just pure text, no sign
auto: false,
easing: "swing",
duration: 400,
width: "100%",
prev: ".jFlowPrev", // must be class, use . sign
next: ".jFlowNext" // must be class, use . sign
};
})(jQuery);
jFlow with Auto Slide Functionality Download
jFlow with Auto Slide and Pause Functionality
Now that you have the slider with auto slide functionality there's a timer that is in effect. Let's take this timer out whenever the user's mouse is outside the slider area. Here's the modified jFlow code below. Download it using the link below.
/* Copyright (c) 2008 Kean Loong Tan http://www.gimiti.com/kltan
* Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
* jFlow
* Version: 1.2 (July 7, 2008)
* Requires: jQuery 1.2+
*/
(function($) {
$.fn.jFlow = function(options) {
var opts = $.extend({}, $.fn.jFlow.defaults, options);
var randNum = Math.floor(Math.random()*11);
var jFC = opts.controller;
var jFS = opts.slideWrapper;
var jSel = opts.selectedWrapper;
var cur = 0;
var timer;
var maxi = $(jFC).length;
// sliding function
var slide = function (dur, i) {
$(opts.slides).children().css({
overflow:"hidden"
});
$(opts.slides + " iframe").hide().addClass("temp_hide");
$(opts.slides).animate({
marginLeft: "-" + (i * $(opts.slides).find(":first-child").width() + "px")
},
opts.duration*(dur),
opts.easing,
function(){
$(opts.slides).children().css({
overflow:"hidden"
});
$(".temp_hide").show();
}
);
}
$(this).find(jFC).each(function(i){
$(this).click(function(){
dotimer();
if ($(opts.slides).is(":not(:animated)")) {
$(jFC).removeClass(jSel);
$(this).addClass(jSel);
var dur = Math.abs(cur-i);
slide(dur,i);
cur = i;
}
});
});
$(opts.slides).before('<div id="'+jFS.substring(1, jFS.length)+'"></div>').appendTo(jFS);
$(opts.slides).find("div").each(function(){
$(this).before('<div class="jFlowSlideContainer"></div>').appendTo($(this).prev());
});
//initialize the controller
$(jFC).eq(cur).addClass(jSel);
var resize = function (x){
$(jFS).css({
position:"relative",
width: opts.width,
height: opts.height,
overflow: "hidden"
});
//opts.slides or #mySlides container
$(opts.slides).css({
position:"relative",
width: $(jFS).width()*$(jFC).length+"px",
height: $(jFS).height()+"px",
overflow: "hidden"
});
// jFlowSlideContainer
$(opts.slides).children().css({
position:"relative",
width: $(jFS).width()+"px",
height: $(jFS).height()+"px",
"float":"left",
overflow:"hidden"
});
$(opts.slides).css({
marginLeft: "-" + (cur * $(opts.slides).find(":eq(0)").width() + "px")
});
}
// sets initial size
resize();
// resets size
$(window).resize(function(){
resize();
});
$(opts.prev).click(function(){
dotimer();
doprev();
});
$(opts.next).click(function(){
dotimer();
donext();
});
var doprev = function (x){
if ($(opts.slides).is(":not(:animated)")) {
var dur = 1;
if (cur > 0)
cur--;
else {
cur = maxi -1;
dur = cur;
}
$(jFC).removeClass(jSel);
slide(dur,cur);
$(jFC).eq(cur).addClass(jSel);
}
}
var donext = function (x){
if ($(opts.slides).is(":not(:animated)")) {
var dur = 1;
if (cur < maxi - 1)
cur++;
else {
cur = 0;
dur = maxi -1;
}
$(jFC).removeClass(jSel);
//$(jFS).fadeOut("fast");
slide(dur, cur);
//$(jFS).fadeIn("fast");
$(jFC).eq(cur).addClass(jSel);
}
}
var dotimer = function (x){
if((opts.auto) == true) {
if(timer != null)
clearInterval(timer);
timer = setInterval(function() {
$(opts.next).click();
}, 10000);
}
}
dotimer();
//Pause/Resume at hover
$(opts.slides).hover(
function() {
clearInterval(timer);
},
function() {
dotimer();
}
);
};
$.fn.jFlow.defaults = {
controller: ".jFlowControl", // must be class, use . sign
slideWrapper : "#jFlowSlide", // must be id, use # sign
selectedWrapper: "jFlowSelected", // just pure text, no sign
auto: false,
easing: "swing",
duration: 400,
width: "100%",
prev: ".jFlowPrev", // must be class, use . sign
next: ".jFlowNext" // must be class, use . sign
};
})(jQuery);
jFlow Auto Slide with Pause Feature Download
Some Extra jFlow Stuff For Ya!
Tip: Notice how we added the code below the dotimer(); call on line 153 before the function's closing "};"
//Pause/Resume at hover
$(opts.slides).hover(
function() {
clearInterval(timer);
},
function() {
dotimer();
}
);
Now when someone hovers over the slider area the time will not be going because the pause is on. Once the mouse leaves the slider the timer resumes and your slider is not paused.
Extra jFlow Auto Hint: To increase the amount of time it takes to for the image to slide increase the following number:
[/code]
var dotimer = function (x){
if((opts.auto) == true) {
if(timer != null)
clearInterval(timer);
timer = setInterval(function() {
$(opts.next).click();
}, 10000);
}
}
If you like this please comment below! Problems? Contact me or comment below!
Related posts:
- Integrity Direct Mortgage Integrity First Financial is an industry leading Mortgage company in Southern California....
- WordPress Lavalamp Navigation Tutorial Lavalamp is an awesome jQuery plug-in that makes really cool effects for WordPress-based menus and navigation links, and as a bonus it is very lightweight. It can be a bit tricky to implement in WordPress, but after you read this tutorial hopefully you'll be implementing it with ease. Follow along and let's get your site's [...]...
-
http://bingoblam.com Slingo Slongo
-
joethefox
-
soto
-
http:/www.dlocc.com Devin Walker
-
Kyle
-
http://www.learningbydesign.biz/2010/ R
-
deilican
-
http://www.jamiewright.net Jamie Wright
-
http:/www.dlocc.com Devin Walker
-
http://www.jamiewright.net Jamie Wright
-
http:/www.dlocc.com Devin Walker
-
Chris
-
http:/www.dlocc.com Devin Walker
-
http://www.fachphoto.com Juan
-
Ben
-
http://www.raghibsuleman.com/ Raghib suleman
-
Brad
-
http://www.hjemmesider.dk Morten
-
http://www.hjemmesider.dk Morten
-
http:/www.dlocc.com Devin Walker
-
Carl
-
Niloc
-
http://www.smirlwebs.com/photography/index.php Alex Williams
-
Raphael
-
http:/www.dlocc.com Devin Walker
-
http:/www.dlocc.com Devin Walker
-
http:/www.dlocc.com Devin Walker
-
http://www.smirlwebs.com/photography/index.php Alex Williams
-
Andy
-
http://whistlephone.com Andy G
-
mssbee
-
http:/www.dlocc.com Devin Walker
-
Andie
-
Carl
-
http:/www.dlocc.com Devin Walker
-
Mauricio Fragale
-
http:/www.dlocc.com Devin Walker
-
Su
-
Ahsan
-
http://www.dezignwhiz.com DezignWhiz
-
http:/www.dlocc.com Devin Walker
-
http:/www.dlocc.com Devin Walker
-
http://pedroserpa.com Pedro Serpa
-
http://music.jeezjaz.com ฟังเพลง
-
http://zforcedesign.com Mike Ziolkowski
-
Mike
-
http://danielvaillancourt.com Dan
-
http://www.philipdahl.com philip
-
Jim Weaver
-
http://www.lasmelidas.org Wilfredo Noyola
-
blink26
-
christina
-
http://www.patrickmaciel.com.br Patrick Maciel
-
http://www.patrickmaciel.com.br Patrick Maciel
-
http://www.patrickmaciel.com.br Patrick Maciel
-
http://www.patrickmaciel.com.br Patrick Maciel
-
http://www.patrickmaciel.com.br Patrick Maciel
-
http://www.patrickmaciel.com.br Patrick Maciel
-
Mihail
-
Gabriel Rodriguez
-
J4jameel
-
http://linkoblast.blogspot.com/ LinkOblast
-
Matthew






