//==================================================================================================== // [插件名称] jQuery agroSlider //---------------------------------------------------------------------------------------------------- // [作者网名] jason // [邮 箱] wangyi@shixun.com // [作者博客] http://www.agronet.com.cn // [更新日期] 2010-5-24 // [版 本 号] ver1.0 // 农网修改版 //==================================================================================================== (function($) { $.fn.agroSlider = function(options) { var options = $.extend({}, $.fn.agroSlider.defaults, options); var pause = false; var _this = this; if (options.fontsize == "12px" || !options.fontsize) { _this.size = "12px"; _this.height = "21px"; _this.right = "6px"; _this.bottom = "10px"; } else if (options.fontsize == "14px") { _this.size = "14px"; _this.height = "23px"; _this.right = "6px"; _this.bottom = "15px"; } var count = jQuery("li", _this).size(); var n = 0; var j = 0; var t; function factory() { _this.css({ position: "relative", zIndex: "0", margin: "0", padding: "0", width: options.width, height: options.height, overflow: "hidden" }) _this.prepend("
"); jQuery("li", _this).css({ width: "100%", height: "100%", overflow: "hidden" }).each(function(i) { jQuery("div", _this).append("" + (i + 1) + "") }); jQuery("img", _this).css({ border: "none", width: "100%", height: "100%" }) resetclass("div a", 0); jQuery("p", _this).each(function(i) { jQuery(this).parent().append(jQuery(this).clone(true)); jQuery(this).html(""); jQuery(this).css({ position: "absolute", margin: "0", padding: "0", zIndex: "1", bottom: "0", left: "0", height: _this.height, width: "100%", background: "#000", opacity: "0.4", overflow: "hidden" }) jQuery(this).next().css({ position: "absolute", margin: "0", padding: "0", zIndex: "2", bottom: "0", left: "0", height: _this.height, lineHeight: _this.height, textIndent: "5px", width: "100%", textDecoration: "none", fontSize: _this.size, color: "#FFFFFF", background: "none", zIndex: "1", opacity: "1", overflow: "hidden" }) if (i != 0) { jQuery(this).hide().next().hide() } }); slide(); addhover(); t = setInterval(autoplay, options.time); } function slide() { jQuery("div a", _this).mouseover(function() { j = jQuery(this).text() - 1; n = j; if (j >= count) { return; } jQuery("li", _this).hide(); jQuery("p", _this).hide(); jQuery("li", _this).eq(j).fadeIn("slow"); jQuery("li", _this).eq(j).find("p").show(); resetclass("div a", j); }); } function addhover() { jQuery(_this).hover(function() { clearInterval(t); }, function() { t = setInterval(autoplay, options.time) }); } function autoplay() { n = n >= (count - 1) ? 0 : ++n; jQuery("div a", _this).eq(n).triggerHandler('mouseover'); } function resetclass(obj, i) { jQuery(obj, _this).css({ float: "left", marginRight: "3px", width: "15px", height: "14px", lineHeight: "15px", textAlign: "center", fontWeight: "800", fontSize: "12px", color: "#000", background: "#FFFFFF", cursor: "pointer", background: "transparent url(" + options.btnimg + ") no-repeat scroll -15px 0" }); jQuery(obj, _this).eq(i).css({ textDecoration: "none", background: "transparent url(" + options.btnimg + ") no-repeat scroll 0 0" }); } factory(); }; //default $.fn.agroSlider.defaults = { width: "300px", height: "200px", fontsize: "12px", right: "0px", bottom: "3px", time: "5000", btnimg: "http://js.agronet.cn/images/flashbutton.gif" } })(jQuery);