(function ($) { $.fn.jlunbo = function (options) { var defaults = { auto: true, autospeed: 5000, animatespeed: 500, containertarget: "ul", elementtarget: "li", toolbarselecter: ".toolbar" }; //默认值 var obj = $.extend(defaults, options); //绑定默认值 var lbobj = $(this); var width = lbobj.find(obj.containertarget + " " + obj.elementtarget).width(); //设置ul宽度 var arrow = (lbobj.find('.pre').length > 0 && lbobj.find('.next').length > 0)//判断箭头元素是否存在 var toolbar = (lbobj.find(obj.toolbarselecter).length > 0); //判断导航小按钮是否存在 var imgcount = lbobj.find(obj.elementtarget).length; //获取li个数 lbobj.find(obj.containertarget).width((width * imgcount) + 'px'); //设置ul宽度以便以后margin-left:负的像素 var nowindex = 1; //初始化插件 if (toolbar) {//如果toolbar存在 var toolbarstr = ''; for (i = 1; i < imgcount + 1; i++) { toolbarstr += ""; } toolbarstr += '
'; lbobj.find(obj.toolbarselecter).append(toolbarstr); var newobj = lbobj.find(obj.toolbarselecter + ' u'); newobj.hover(function () { nowindex = newobj.index(this) + 1 showing(nowindex); }); } if (arrow) {//如果箭头存在 lbobj.find('.pre').click(function () { nowindex < 2 ? nowindex = imgcount : nowindex--; showing(nowindex); }); lbobj.find('.next').click(function () { nowindex > (imgcount - 1) ? nowindex = 1 : nowindex++; showing(nowindex); }); } function showing(imgid) { lbobj.find(obj.containertarget).stop().animate({ marginleft: (-width * (imgid - 1)) + "px" }, obj.animatespeed); if (toolbar) { var newobj = lbobj.find(obj.toolbarselecter + ' u'); newobj.removeclass('active'); newobj.eq(imgid - 1).addclass('active'); } }; if (obj.auto) { function autochange() { nowindex > (imgcount - 1) ? nowindex = 1 : nowindex++; showing(nowindex); }; var st = setinterval(autochange, obj.autospeed); lbobj.hover(function () { clearinterval(st); }, function () { st = setinterval(autochange, obj.autospeed) }); } showing(nowindex); } })(jquery); (function ($) { $.fn.jhuaguo = function (options) { var defaults = { speed: 100, commonb: 0, togot: 10 }; //默认值 var obj = $.extend(defaults, options); //绑定默认值 var myobj = $(this); myobj.parent().hover( function () { myobj.animate({ marginbottom: (obj.commonb + obj.togot) + "px" }, obj.speed); }, function () { myobj.animate({ marginbottom: obj.commonb + "px" }, obj.speed); } ) } })(jquery);