(function($){ //返回顶部和底部插件 $.fn.extend({ goTopBootom:function (options){ //默认参数 var defaults = { "upBtn":".up", //被点击返回顶部的按钮 "downBtn":".down", //被点击返回底部的按钮 "inTms":300, //此功能元素出现的时间 "outTms":300, //此功能元素隐藏的时间 "speed":500 //返回顶部或者底部的速度 }; var options = $.extend(defaults,options) return this.each(function(){ var _this = $(this); var oHtmlBody = $('html,body'); var oBodyH = document.body.clientHeight; var oUp = $(this).find(options.upBtn); var oDown = $(this).find(options.downBtn); $(this).css("top",window.screen.availHeight/2-100+"px"); $(window).scroll(function() { if($(window).scrollTop() >= 200){ _this.fadeIn(options.inTms); }else{ _this.fadeOut(options.inTms); } }); oUp.click(function(){oHtmlBody.animate({scrollTop: '0px'}, options.speed);}); oDown.click(function(){oHtmlBody.animate({scrollTop: oBodyH + 'px'}, options.speed);}); }); }, //解决ie6下fixed插件 ie6fixedbug: function () { return this.each(function(){ var m = (window.screen.height - $(this).height()) / 3; var obj = $(this); $(window).scroll(function () { obj.css("top",(document.body.scrollTop || document.documentElement.scrollTop) + m + 'px'); }); $(window).resize(function () { obj.css("top",(document.body.scrollTop || document.documentElement.scrollTop) + m + 'px'); }); }); } }); }(jQuery));