最近项目需要,于是简单写了个判断滚动条置底的插件代码,欢迎拍砖交流!
代码如下:
//滚动条滚动到底部了 --by xqs (function ($) { $.fn.scrollBot = function (opt, callback) { //diffY:距离底部像素值 var opts = (arguments.length == 1) ? {diffY: 0} : $.extend({diffY: 0}, opt); var fun = (arguments.length == 1) ? arguments[0] :arguments[1]; return this.each(function () { var _this = $(this); _this.bind("scroll", function () { var scrollTop = _this.scrollTop(); var clientH = _this.height(); var contentH = 0; $.each(_this.children(":visible"), function () { contentH += $(this).outerHeight(true); }); if (scrollTop + clientH + opts.diffY >= contentH) { fun.apply(this,arguments); } }) }); }; })(jQuery);
调用方式:
$("#content").scrollBot({"diffY":100},function(){ //diffY:距离底部像素值 //console.log("滚动条到底了···") } );