(function($){ $.fn.ScrollNav = function(options){ var opts = $.extend({}, $.fn.ScrollNav.defualts, options); var _this = $(this); $.fn.ScrollNav.defaultValue(opts,$(this));//还原默认 $(this).hover(function(){ var leftValue = $.fn.ScrollNav.countLeft(opts,$(this)); //统计左侧的Value var widthValue = $(this).width(); if($(this).find("li").length>0){ $.fn.ScrollNav.openSubNav(opts,$(this)); } $.fn.ScrollNav.setScroll(opts,widthValue,leftValue);//添加动画 },function(){ if($(this).find("li").length>0){ $.fn.ScrollNav.closeSubNav(opts,$(this)); } $.fn.ScrollNav.defaultValue(opts,$(this));//还原默认 }); } //plugin defaults $.fn.ScrollNav.defualts ={ scrollObj:".nav > .scrollObj",//滑动的父对象 speed:"slow" //子菜单的宽度 } //子插件:获取左侧Value $.fn.ScrollNav.countLeft = function(opts,liThis){ var liIndex = liThis.index(); var leftValue = 0; for(i=0;i