jQuery实现的自动加载页面功能示例
(编辑:jimmy 日期: 2024/11/19 浏览:3 次 )
本文实例讲述了jQuery实现的自动加载页面功能。分享给大家供大家参考,具体如下:
demo.html:
<li style="opacity:0;-moz-opacity: 0;filter: alpha(opacity=0);"><p>---------------</p></li> <li style="opacity:0;-moz-opacity: 0;filter: alpha(opacity=0);"><p>阅谁问君诵,水落清香浮</p></li> <li style="opacity:0;-moz-opacity: 0;filter: alpha(opacity=0);"><p>阅谁问君诵,水落清香浮</p></li> <li style="opacity:0;-moz-opacity: 0;filter: alpha(opacity=0);"><p>阅谁问君诵,水落清香浮</p></li> <li style="opacity:0;-moz-opacity: 0;filter: alpha(opacity=0);"><p>阅谁问君诵,水落清香浮</p></li> <li style="opacity:0;-moz-opacity: 0;filter: alpha(opacity=0);"><p>阅谁问君诵,水落清香浮</p></li> <li style="opacity:0;-moz-opacity: 0;filter: alpha(opacity=0);"><p>阅谁问君诵,水落清香浮</p></li> <li style="opacity:0;-moz-opacity: 0;filter: alpha(opacity=0);"><p>阅谁问君诵,水落清香浮</p></li> <li style="opacity:0;-moz-opacity: 0;filter: alpha(opacity=0);"><p>阅谁问君诵,水落清香浮</p></li> <li style="opacity:0;-moz-opacity: 0;filter: alpha(opacity=0);"><p>+++++++++++++++</p></li>
scrollpagination.js:
(function( $ ){ $.fn.scrollPagination = function(options) { var opts = $.extend($.fn.scrollPagination.defaults, options); var target = opts.scrollTarget; if (target == null){ target = obj; } opts.scrollTarget = target; return this.each(function() { $.fn.scrollPagination.init($(this), opts); }); }; $.fn.stopScrollPagination = function(){ return this.each(function() { $(this).attr('scrollPagination', 'disabled'); }); }; $.fn.scrollPagination.loadContent = function(obj, opts){ var target = opts.scrollTarget; var mayLoadContent = $(target).scrollTop()+opts.heightOffset >= $(document).height() - $(target).height(); if (mayLoadContent){ if (opts.beforeLoad != null){ opts.beforeLoad(); } $(obj).children().attr('rel', 'loaded'); $.ajax({ type: 'POST', url: opts.contentPage, data: opts.contentData, success: function(data){ $(obj).append(data); var objectsRendered = $(obj).children('[rel!=loaded]'); if (opts.afterLoad != null){ opts.afterLoad(objectsRendered); } }, dataType: 'html' }); } }; $.fn.scrollPagination.init = function(obj, opts){ var target = opts.scrollTarget; $(obj).attr('scrollPagination', 'enabled'); $(target).scroll(function(event){ if ($(obj).attr('scrollPagination') == 'enabled'){ $.fn.scrollPagination.loadContent(obj, opts); } else { event.stopPropagation(); } }); $.fn.scrollPagination.loadContent(obj, opts); }; $.fn.scrollPagination.defaults = { 'contentPage' : null, 'contentData' : {}, 'beforeLoad': null, 'afterLoad': null , 'scrollTarget': null, 'heightOffset': 0 }; })( jQuery );
index.html:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <script type="text/javascript" src="/UploadFiles/2021-04-02/jquery-1.10.1.min.js">效果图如下:
更多关于jQuery相关内容感兴趣的读者可查看本站专题:《jQuery扩展技巧总结》、《jQuery常用插件及用法总结》、《jQuery拖拽特效与技巧总结》、《jQuery表格(table)操作技巧汇总》、《jquery中Ajax用法总结》、《jQuery常见经典特效汇总》、《jQuery动画与特效用法总结》及《jquery选择器用法总结》
希望本文所述对大家jQuery程序设计有所帮助。
下一篇:jQuery简单实现中间浮窗效果