为了账号安全,请及时绑定邮箱和手机立即绑定

php,jquery做成瀑布效果

标签:
JQuery

1.test.html

<!

DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<

html>

<

head>

<

meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<

title>好看的瀑布</title>

<

script type="text/javascript" language="javascript" src="js/jquery-1.8.0.js"></script>

<

script type="text/javascript" language="javascript" src="js/jquery-1.8.0.min.js"></script>

<

link type="text/css" rel="stylesheet" href="css/waterfall.css" />

<

script type="text/javascript" language="javascript" src="js/waterfall.js"></script>

</

head>

<

body>

<ul id="stage">

<li></li>

<li></li>

<li></li>

<li></li>

</ul>

</body>

</html>

 

2.waterfall.js

$(document).ready(function(){

loadMore();

});

 

 

function

loadMore()

{

$.ajax({

url : 'test.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(iTempHeight=-1 ||iHeight >iTempHeight){

iHeight=iTempHeight;

$row=$(this);

}

});

$item=$('<div><img class="lazyload" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC" data-original="'+oProduct.image+'" border="1"><br>'+oProduct.title+'</div>').hide();

$row.append($item);

$item.fadeIn();

}

}

}

});

}

 

3.waterfall.css

body

{text-align:center;}

/*Download by http://www.codefans.net*/

#stage

{ margin:0 auto; padding:0; width:880px; }

#stage

li{ margin:0; padding:0; list-style:none;float:left; width:220px;}

#stage

li div{ font-size:12px; padding:10px; color:#999999; text-align:left; } 

 

4.test.php

<?php

$data = array();

$data[] = array('image'=>'images/1.jpg','title'=>'111111111');

$data[] = array('image'=>'images/2.jpg','title'=>'222222222');

$data[] = array('image'=>'images/3.jpg','title'=>'333333333');

$data[] = array('image'=>'images/4.jpg','title'=>'444444444');

$data[] = array('image'=>'images/5.jpg','title'=>'555555555');

$data[] = array('image'=>'images/6.jpg','title'=>'666666666');

$data[] = array('image'=>'images/7.jpg','title'=>'777777777');

$data[] = array('image'=>'images/8.jpg','title'=>'888888888');

$data[] = array('image'=>'images/9.jpg','title'=>'999999999');

$data[] = array('image'=>'images/10.jpg','title'=>'10101010');

$data[] = array('image'=>'images/11.jpg','title'=>'111111111');

$data[] = array('image'=>'images/12.jpg','title'=>'12121212');

$data[] = array('image'=>'images/13.jpg','title'=>'13131313');

$data[] = array('image'=>'images/14.jpg','title'=>'14141414');

$data[] = array('image'=>'images/15.jpg','title'=>'15151515');

$data[] = array('image'=>'images/16.jpg','title'=>'16161616');

$data[] = array('image'=>'images/17.jpg','title'=>'17171717');

$data[] = array('image'=>'images/18.jpg','title'=>'18181818');

$data[] = array('image'=>'images/19.jpg','title'=>'19191919');

$data[] = array('image'=>'images/20.jpg','title'=>'20202020');

$keys =array_rand($data,10);

$json=array();

foreach ($keys as $key){

$json[]=$data[$key];

}

echo json_encode($json);

?>


点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
  • 推荐
  • 评论
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消