下拉滚动条或鼠标滚轮滚动到页面底部时, 动态即时加载新内容。
后台用 json 传输数据, 示例程序中只写了示例数组。数据也只设置了两个属性, 需根据实际应用改写。
页面用了 ul li 做为容器, 每个 li 表示一列
<ul id="stage"> <li></li> <li></li> <li></li> PHP和Jquery和ajax实现下拉淡出瀑布流效果(无需插件) <li></li> </ul>
JS代码
/* @版本日期: 版本日期: 2012年4月11日 @著作权所有: 1024 intelligence ( http://www.1024i.com ) 获得使用本类库的许可, 您必须保留著作权声明信息. 报告漏洞,意见或建议, 请联系 Lou Barnes(iua1024@gmail.com) */ $(document).ready(function(){ loadMore(); }); $(window).scroll(function(){ // 当滚动到最底部以上100像素时, 加载新内容 if ($(document).height() - $(this).scrollTop() - $(this).height()<100) loadMore(); }); function loadMore() { $.ajax({ url : 'data.php', dataType : 'json', success : function(json) { if(typeof json == 'object') { var oProduct, $row, iHeight, iTempHeight; for(var i=0, l=json.length; i<l; i++) { oProduct = json[i]; // 找出当前高度最小的列, 新内容添加到该列 iHeight = -1; $('#stage li').each(function(){ iTempHeight = Number( $(this).height() ); if(iHeight==-1 || iHeight>iTempHeight) { iHeight = iTempHeight; $row = $(this); } }); $item = $('<div><img src="/static/imghwm/default1.png" data-src="'+oProduct.image+'" class="lazy"+oProduct.image+'" border="0" alt="jQuery向下滚动即时加载内容实现的瀑布流效果_php实例" ><br />'+oProduct.title+'</div>').hide(); $row.append($item); $item.fadeIn(); } } } }); }
下面再给大家分享一段代码:PHP Jquery和ajax相结合实现下拉淡出瀑布流效果
我的风格,废话不多说,感兴趣的朋友直接看下文代码:
前台:
<br><?php <br>$category=$this->getMyVal('category',$_GET);<br>$xiaohuaList=Xiaohua::model()->getXiaohao($category); //打开页面默认显示的数据<br>?><br><br><div id="waterfall"> <?php foreach ($xiaohuaList as $xiaohua):?> <?php $q_id=$xiaohua->id;?> <div class="cell m-bg item-h border_h"> <div class="border-solid-b padding-b-5 text-center"><span class="g-bg glyphicon glyphicon-sunglasses margin-r-5" aria-hidden="true"></span><strong class="color-5 fx_t_<?php echo $q_id;?>"><?php echo CHtml::encode($xiaohua->title);?></strong></div> <div class="padding-t-5 fx_c_<?php echo $q_id;?>"><?php echo $xiaohua->content;?></div> <div class="padding-t-5 text-right"><span onclick="fx(<?php echo $q_id;?>);" class="fx cursor_p" data-id="<?php echo $q_id;?>"><span class="g-bg glyphicon glyphicon-share-alt margin-r-5" aria-hidden="true"></span>分享</span></div> </div> <?php endforeach;?> </div> <script> var opt={ getResource:function(index,render){//index为已加载次数,render为渲染接口函数,接受一个dom集合或jquery对象作为参数。通过ajax等异步方法得到的数据可以传入该接口进行渲染,如 render(elem) var html=''; var _url='<?php echo $this->createUrl('listXiaohua');?>'; $.ajax({ type: "get", url: _url, dataType : "json", async:false, success: function(data){ for( var i in data){ var q_id=data[i].id; html+='<div class="cell m-bg item-h border_h"><div class="border-solid-b padding-b-5 text-center"><span class="g-bg glyphicon glyphicon-sunglasses margin-r-5" aria-hidden="true"></span><strong class="color-5 fx_t_'+q_id+'">'+data[i].title+'</strong></div><div class="padding-t-5 fx_c_'+q_id+'">'+data[i].content+'</div>' +'<div class="padding-t-5 text-right"><span onclick="fx('+q_id+');" class="fx cursor_p" data-id="'+q_id+'"><span class="g-bg glyphicon glyphicon-share-alt margin-r-5" aria-hidden="true"></span>分享</span></div></div>'; } }}); return $(html); }, column_width:376, column_space:10, auto_imgHeight:true, insert_type:1 } $('#waterfall').waterfall(opt); </script>
后台:
public function actionListXiaohua() { $xiaohuaList=Xiaohua::model()->getXiaohua();//获取笑话信息 echo CJSON::encode($xiaohuaList); }
js:
;(function($){ var //参数 setting={ column_width:240,//列宽 column_className:'waterfall_column',//列的类名 column_space:2,//列间距 cell_selector:'.cell',//要排列的砖块的选择器,context为整个外部容器 img_selector:'img',//要加载的图片的选择器 auto_imgHeight:true,//是否需要自动计算图片的高度 fadein:true,//是否渐显载入 fadein_speed:600,//渐显速率,单位毫秒 insert_type:1, //单元格插入方式,1为插入最短那列,2为按序轮流插入 getResource:function(index){ } //获取动态资源函数,必须返回一个砖块元素集合,传入参数为加载的次数 }, // waterfall=$.waterfall={},//对外信息对象 $waterfall=null;//容器 waterfall.load_index=0, //加载次数 $.fn.extend({ waterfall:function(opt){ opt=opt||{}; setting=$.extend(setting,opt); $waterfall=waterfall.$waterfall=$(this); waterfall.$columns=creatColumn(); render($(this).find(setting.cell_selector).detach(),false); //重排已存在元素时强制不渐显 waterfall._scrollTimer2=null; $(window).bind('scroll',function(){ clearTimeout(waterfall._scrollTimer2); waterfall._scrollTimer2=setTimeout(onScroll,300); }); waterfall._scrollTimer3=null; $(window).bind('resize',function(){ clearTimeout(waterfall._scrollTimer3); waterfall._scrollTimer3=setTimeout(onResize,300); }); } }); function creatColumn(){//创建列 waterfall.column_num=calculateColumns();//列数 //循环创建列 var html=''; for(var i=0;i<waterfall.column_num;i++){ html+='<div class="'+setting.column_className+'" style="width:'+setting.column_width+'px; display:inline-block; *display:inline;zoom:1; margin-left:'+setting.column_space/2+'px;margin-right:'+setting.column_space/2+'px; vertical-align:top; overflow:hidden"></div>'; } $waterfall.prepend(html);//插入列 return $('.'+setting.column_className,$waterfall);//列集合 } function calculateColumns(){//计算需要的列数 var num=Math.floor(($waterfall.innerWidth())/(setting.column_width+setting.column_space)); if(num<1){ num=1; } //保证至少有一列 return num; } function render(elements,fadein){//渲染元素 if(!$(elements).length) return;//没有元素 var $columns = waterfall.$columns; $(elements).each(function(i){ if(!setting.auto_imgHeight||setting.insert_type==2){//如果给出了图片高度,或者是按顺序插入,则不必等图片加载完就能计算列的高度了 if(setting.insert_type==1){ insert($(elements).eq(i),setting.fadein&&fadein);//插入元素 }else if(setting.insert_type==2){ insert2($(elements).eq(i),i,setting.fadein&&fadein);//插入元素 } return true;//continue } if($(this)[0].nodeName.toLowerCase()=='img'||$(this).find(setting.img_selector).length>0){//本身是图片或含有图片 var image=new Image; var src=$(this)[0].nodeName.toLowerCase()=='img'?$(this).attr('src'):$(this).find(setting.img_selector).attr('src'); image.onload=function(){//图片加载后才能自动计算出尺寸 image.onreadystatechange=null; if(setting.insert_type==1){ insert($(elements).eq(i),setting.fadein&&fadein);//插入元素 }else if(setting.insert_type==2){ insert2($(elements).eq(i),i,setting.fadein&&fadein);//插入元素 } image=null; } image.onreadystatechange=function(){//处理IE等浏览器的缓存问题:图片缓存后不会再触发onload事件 if(image.readyState == "complete"){ image.onload=null; if(setting.insert_type==1){ insert($(elements).eq(i),setting.fadein&&fadein);//插入元素 }else if(setting.insert_type==2){ insert2($(elements).eq(i),i,setting.fadein&&fadein);//插入元素 } image=null; } } image.src=src; }else{//不用考虑图片加载 if(setting.insert_type==1){ insert($(elements).eq(i),setting.fadein&&fadein);//插入元素 }else if(setting.insert_type==2){ insert2($(elements).eq(i),i,setting.fadein&&fadein);//插入元素 } } }); } function public_render(elems){//ajax得到元素的渲染接口 render(elems,true); } function insert($element,fadein){//把元素插入最短列 if(fadein){//渐显 $element.css('opacity',0).appendTo(waterfall.$columns.eq(calculateLowest())).fadeTo(setting.fadein_speed,1); }else{//不渐显 $element.appendTo(waterfall.$columns.eq(calculateLowest())); } } function insert2($element,i,fadein){//按序轮流插入元素 if(fadein){//渐显 $element.css('opacity',0).appendTo(waterfall.$columns.eq(i%waterfall.column_num)).fadeTo(setting.fadein_speed,1); }else{//不渐显 $element.appendTo(waterfall.$columns.eq(i%waterfall.column_num)); } } function calculateLowest(){//计算最短的那列的索引 var min=waterfall.$columns.eq(0).outerHeight(),min_key=0; waterfall.$columns.each(function(i){ if($(this).outerHeight()<min){ min=$(this).outerHeight(); min_key=i; } }); return min_key; } function getElements(){//获取资源 $.waterfall.load_index++; return setting.getResource($.waterfall.load_index,public_render); } waterfall._scrollTimer=null;//延迟滚动加载计时器 function onScroll(){//滚动加载 clearTimeout(waterfall._scrollTimer); waterfall._scrollTimer=setTimeout(function(){ var $lowest_column=waterfall.$columns.eq(calculateLowest());//最短列 var bottom=$lowest_column.offset().top+$lowest_column.outerHeight();//最短列底部距离浏览器窗口顶部的距离 var scrollTop=document.documentElement.scrollTop||document.body.scrollTop||0;//滚动条距离 var windowHeight=document.documentElement.clientHeight||document.body.clientHeight||0;//窗口高度 if(scrollTop>=bottom-windowHeight){ render(getElements(),true); } },100); } function onResize(){//窗口缩放时重新排列 if(calculateColumns()==waterfall.column_num) return; //列数未改变,不需要重排 var $cells=waterfall.$waterfall.find(setting.cell_selector); waterfall.$columns.remove(); waterfall.$columns=creatColumn(); render($cells,false); //重排已有元素时强制不渐显 } })(jQuery);
以上代码分为两部分给大家介绍了PHP和Jquery和ajax实现下拉淡出瀑布流效果,代码比较简单,附有注释,如有bug欢迎提出,脚本之家小编会在第一时间和大家联系的。谢谢!

PHP 로깅은 웹 애플리케이션을 모니터링하고 디버깅하고 중요한 이벤트, 오류 및 런타임 동작을 캡처하는 데 필수적입니다. 시스템 성능에 대한 귀중한 통찰력을 제공하고 문제를 식별하며 더 빠른 문제 해결을 지원합니다.

Laravel은 직관적 인 플래시 방법을 사용하여 임시 세션 데이터 처리를 단순화합니다. 응용 프로그램에 간단한 메시지, 경고 또는 알림을 표시하는 데 적합합니다. 데이터는 기본적으로 후속 요청에만 지속됩니다. $ 요청-

PHP 클라이언트 URL (CURL) 확장자는 개발자를위한 강력한 도구이며 원격 서버 및 REST API와의 원활한 상호 작용을 가능하게합니다. PHP CURL은 존경받는 다중 프로모토콜 파일 전송 라이브러리 인 Libcurl을 활용하여 효율적인 execu를 용이하게합니다.

Laravel은 간결한 HTTP 응답 시뮬레이션 구문을 제공하여 HTTP 상호 작용 테스트를 단순화합니다. 이 접근법은 테스트 시뮬레이션을보다 직관적으로 만들면서 코드 중복성을 크게 줄입니다. 기본 구현은 다양한 응답 유형 단축키를 제공합니다. Illuminate \ support \ Facades \ http를 사용하십시오. http :: 가짜 ([ 'google.com'=> 'Hello World', 'github.com'=> [ 'foo'=> 'bar'], 'forge.laravel.com'=>

고객의 가장 긴급한 문제에 실시간 인스턴트 솔루션을 제공하고 싶습니까? 라이브 채팅을 통해 고객과 실시간 대화를 나누고 문제를 즉시 해결할 수 있습니다. 그것은 당신이 당신의 관습에 더 빠른 서비스를 제공 할 수 있도록합니다.

Alipay PHP ...

기사는 PHP 5.3에 도입 된 PHP의 LSB (Late STATIC BING)에 대해 논의하여 정적 방법의 런타임 해상도가보다 유연한 상속을 요구할 수있게한다. LSB의 실제 응용 프로그램 및 잠재적 성능

이 기사에서는 프레임 워크에 사용자 정의 기능 추가, 아키텍처 이해, 확장 지점 식별 및 통합 및 디버깅을위한 모범 사례에 중점을 둡니다.


핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

Eclipse용 SAP NetWeaver 서버 어댑터
Eclipse를 SAP NetWeaver 애플리케이션 서버와 통합합니다.

드림위버 CS6
시각적 웹 개발 도구

안전한 시험 브라우저
안전한 시험 브라우저는 온라인 시험을 안전하게 치르기 위한 보안 브라우저 환경입니다. 이 소프트웨어는 모든 컴퓨터를 안전한 워크스테이션으로 바꿔줍니다. 이는 모든 유틸리티에 대한 액세스를 제어하고 학생들이 승인되지 않은 리소스를 사용하는 것을 방지합니다.

WebStorm Mac 버전
유용한 JavaScript 개발 도구

SecList
SecLists는 최고의 보안 테스터의 동반자입니다. 보안 평가 시 자주 사용되는 다양한 유형의 목록을 한 곳에 모아 놓은 것입니다. SecLists는 보안 테스터에게 필요할 수 있는 모든 목록을 편리하게 제공하여 보안 테스트를 더욱 효율적이고 생산적으로 만드는 데 도움이 됩니다. 목록 유형에는 사용자 이름, 비밀번호, URL, 퍼징 페이로드, 민감한 데이터 패턴, 웹 셸 등이 포함됩니다. 테스터는 이 저장소를 새로운 테스트 시스템으로 간단히 가져올 수 있으며 필요한 모든 유형의 목록에 액세스할 수 있습니다.

뜨거운 주제



