function picRoll(){ var defaultConfig = { eleFather: '.banner', //容器标签 父元素 最外围标签 botDiv: '.control', //图解文字所在标签 eleSmallClass: 'on', //下方的缩略图选中时的样式 // eleBottom: null, //下方的缩略图 rollLeft: null, //向左转标签 rollRight: null, //向右转标签 time:4000 //图片切换时间间隔,默认3000毫秒 } config = $.extend({},defaultConfig); var pointer = 0; var $imgUl = $(config.eleFather).find('ul:first');//检索获取图片ul列表 var $botDiv = $(config.botDiv); //检索获取缩略图ul列表 var imgWidth = $imgUl.find('img').height(); var imgNum = $imgUl.find('img').length; var arrInter = []; //根据图片数量自匹配imgUl的宽 console.log($imgUl) $imgUl.width(imgWidth*imgNum); //定时器 arrInter.push(setInterval(function(){_move(++pointer)},config.time)); $(config.eleFather).mouseover(function(){ _clearInter(arrInter); }).mouseout(function(){ arrInter.push(setInterval(function(){_move(++pointer)},config.time)); }) //左右点击按钮的hover透明度效果 var opa = $(config.rollLeft).css('opacity'); $(config.rollLeft+","+config.rollRight).hover(function(){ $(this).css('opacity',1); _clearInter(arrInter); },function(){ $(this).css('opacity',opa); arrInter.push(setInterval(function(){_move(++pointer)},config.time)); }) //向左,向右滚动点击效果 $(config.rollLeft).click(function(){ _move(--pointer); }) $(config.rollRight).click(function(){ _move(++pointer); }) //底部缩略图hover效果 $botDiv.find('span').hover(function(){ pointer = $(this).index(); _move(pointer); _clearInter(arrInter); },function(){ arrInter.push(setInterval(function(){_move(++pointer)},config.time)); }) function _move(poi){ poi = poi>=imgNum?0:poi; poi = poi<0?imgNum-1:poi; $imgUl.find('li').eq(poi).fadeIn('slow').siblings().hide(); $botDiv.find('span').removeClass(config.eleSmallClass).eq(poi).addClass(config.eleSmallClass); //图示文字切换 pointer = poi; }_move(0) function _clearInter(arrInter){ for (var i = arrInter.length - 1; i >= 0; i--) { clearInterval(arrInter[i]); } } }