首先,感谢大家对于see source 的支持,希望您能继续给予关注。
昨天,系统更新了"前端框架专区"的广告栏(左下角,可以看下效果),这个轮播插件(jquery.slideBox)是在网上搜索到的,很好用,也很小,只有100行(未压缩)左右的代码量,扩展、修改都很方便。另外经测试,浏览器兼容性也是不错的,过度效果也很好,再此推荐给大家。 作者是 开源中国 的 迦楠。
功能:
1.支持上下、左右俩个方向滚动。
2.可设置滚动间隔时间和滚动持续时间。
3.提供了swing 和 linear俩个滚动效果
4.可设置初始焦点
5.可自动隐藏点选按钮
6.提供标题栏,并可隐藏
您可以从这里下载。里边有详细的demo。
演示地址: http://ishere.cn/demo/jquery.slidebox/
该插件涉及俩个文件:jquery.slideBox.css 和 jquery.slideBox.js
jquery.slideBox.css
@charset "utf-8";
html, body { font-family:"微软雅黑"}
/*
* jQuery图片轮播(焦点图)插件
* ADD.JENA.201206291027
* EDIT.JENA.201206300904
* Author: jena
* Demo: http://ishere.cn/demo/jquery.slidebox/
*/
div.slideBox{ position:relative; width:670px; height:300px; overflow:hidden;}
div.slideBox ul.items{ position:absolute; float:left; background:none; list-style:none; padding:0px; margin:0px;}
div.slideBox ul.items li{ float:left; background:none; list-style:none; padding:0px; margin:0px;}
div.slideBox ul.items li a{ float:left; line-height:normal !important; padding:0px !important; border:none/*For IE.ADD.JENA.201206300844*/;}
div.slideBox ul.items li a img{ margin:0px !important; padding:0px !important; display:block; border:none/*For IE.ADD.JENA.201206300844*/;}
div.slideBox div.tips{ position:absolute; bottom:0px; width:100%; height:50px; background-color:#000; overflow:hidden;}
div.slideBox div.tips div.title{ position:absolute; left:0px; top:0px; height:100%;}
div.slideBox div.tips div.title a{ color:#FFF; font-size:18px; line-height:50px; margin-left:10px; text-decoration:none;}
div.slideBox div.tips div.title a:hover{ text-decoration:underline !important;}
div.slideBox div.tips div.nums{ position:absolute; right:0px; top:0px; height:100%;}
div.slideBox div.tips div.nums a{ display:inline-block; >float:left/*For IE.ADD.JENA.201206300844*/; width:20px; height:20px; background-color:#FFF; text-indent:-99999px; margin:15px 10px 0px 0px;}
div.slideBox div.tips div.nums a.active{ background-color:#093;}
jquery.slideBox.js
/*
* jQuery图片轮播(焦点图)插件
* ADD.JENA.201206291027
* EDIT.JENA.201206300904
* EDIT.JENA.201207051027
* EDIT.JENA.201208090849
* EDIT.JENA.201303141312
* Version: 1.2.0314
* Author: jena
* Demo: http://ishere.cn/demo/jquery.slidebox/
*/
(function($) {
$.fn.slideBox = function(options) {
//默认参数
var defaults = {
direction : 'left',//设置滚动方向。left,top
duration : 0.6,//滚动持续时间,单位:秒
easing : 'swing',//滚动特效。swing,linear
delay : 3,//滚动间隔时间,单位:秒
startIndex : 0,//设置初始焦点
hideClickBar : true,//是否自动隐藏点选按键
clickBarRadius : 5,//点选按钮边框半径,单位:px
hideBottomBar : false,//是否隐藏底层的标题栏
width : null,
height : null
};
var settings = $.extend(defaults, options || {});
//计算相关数据
var wrapper = $(this), ul = wrapper.children('ul.items'), lis = ul.find('li'), firstPic = lis.first().find('img');
var li_num = lis.size(), li_height = 0, li_width = 0;
//定义滚动顺序:ASC/DESC.ADD.JENA.201208081718
var order_by = 'ASC';
//初始化
var init = function(){
if(!wrapper.size()) return false;
//手动设定值优先.ADD.JENA.201303141309
li_height = settings.height ? settings.height : lis.first().height();
li_width = settings.width ? settings.width : lis.first().width();
wrapper.css({width: li_width+'px', height:li_height+'px'});
lis.css({width: li_width+'px', height:li_height+'px'});//ADD.JENA.201207051027
if (settings.direction == 'left') {
ul.css('width', li_num * li_width + 'px');
} else {
ul.css('height', li_num * li_height + 'px');
}
ul.find('li:eq('+settings.startIndex+')').addClass('active');
if(!settings.hideBottomBar){//ADD.JENA.201208090859
var tips = $('<div class="tips"></div>').css('opacity', 0.6).appendTo(wrapper);
var title = $('<div class="title"></div>').html(function(){
var active = ul.find('li.active').find('a'), text = active.attr('title'), href = active.attr('href');
return $('<a>').attr('href', href).text(text);
}).appendTo(tips);
var nums = $('<div class="nums"></div>').hide().appendTo(tips);
lis.each(function(i, n) {
var a = $(n).find('a'), text = a.attr('title'), href = a.attr('href'), css = '';
i == settings.startIndex && (css = 'active');
$('<a>').attr('href', href).text(text).addClass(css).css('borderRadius', settings.clickBarRadius+'px').mouseover(function(){
$(this).addClass('active').siblings().removeClass('active');
ul.find('li:eq('+$(this).index()+')').addClass('active').siblings().removeClass('active');
start();
stop();
}).appendTo(nums);
});
if(settings.hideClickBar){//ADD.JENA.201206300847
tips.hover(function(){
nums.animate({top: '0px'}, 'fast');
}, function(){
nums.animate({top: tips.height()+'px'}, 'fast');
});
nums.show().delay(2000).animate({top: tips.height()+'px'}, 'fast');
}else{
nums.show();
}
}
lis.size()>1 && start();
}
//开始轮播
var start = function() {
var active = ul.find('li.active'), active_a = active.find('a');
var index = active.index();
if(settings.direction == 'left'){
offset = index * li_width * -1;
param = {'left':offset + 'px' };
}else{
offset = index * li_height * -1;
param = {'top':offset + 'px' };
}
wrapper.find('.nums').find('a:eq('+index+')').addClass('active').siblings().removeClass('active');
wrapper.find('.title').find('a').attr('href', active_a.attr('href')).text(active_a.attr('title'));
ul.stop().animate(param, settings.duration*1000, settings.easing, function() {
active.removeClass('active');
if(order_by=='ASC'){
if (active.next().size()){
active.next().addClass('active');
}else{
order_by = 'DESC';
active.prev().addClass('active');
}
}else if(order_by=='DESC'){
if (active.prev().size()){
active.prev().addClass('active');
}else{
order_by = 'ASC';
active.next().addClass('active');
}
}
});
wrapper.data('timeid', window.setTimeout(start, settings.delay*1000));
};
//停止轮播
var stop = function() {
window.clearTimeout(wrapper.data('timeid'));
};
//鼠标经过事件
wrapper.hover(function(){
stop();
}, function(){
window.setTimeout(start, settings.delay*1000);//ADD.JENA.201303141309
});
//首张图片加载完毕后执行初始化
var imgLoader = new Image();
imgLoader.onload = function(){
imgLoader.onload = null;
init();
}
imgLoader.src = firstPic.attr('src');
};
})(jQuery);