<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>超简易瀑布流</title>
<style>
body, div, dl, dt, dd, ul, ol, li, h1, h2, h3, h4, h5, h6, pre, form, fieldset, input, textarea, p, blockquote, th, td ,span, object, iframe{ padding: 0; margin: 0; } table { border-collapse: collapse; border-spacing: 0; }
fieldset, img { border: 0; }
ol, ul { list-style: none; }
h1, h2, h3, h4, h5, h6 { font-weight: normal; font-size: 100%; }
q:before, q:after { content:""; }
.clearfix:after{ content:""; height:0; visibility:hidden; display:block; clear:both;}
.clearfix{ zoom:1;}

/*start*/
.box{width:1000px; margin:0 auto auto auto;}
.add-btn{ display:block; margin:20px auto auto auto; width:90px; height:30px; text-align:center; line-height:30px; font-size:16px; background:#C33; border-radius:10px; text-decoration:none; color:#fff;}
.column img{width:100%;}
</style>
</head>

<body>
<div class="box ">
<div id="waterfall" class="clearfix">

</div>
</div>
<a href="javascript:;" class="add-btn" id="add">加载更多</a>
</body>
<script>
window.onload = function(){
document.getElementById("add").onclick = function(){
waterFall();
}
}

function waterFall(){
var wf = document.getElementById("waterfall"),
wf_len = 4, //列数
wf_data = 2, //每列添加数据条数
wf_space = 10,//每列左右间隔,单位px
wf_bottom = 20,//每列元素上下间隔,单位px
wf_boxWidth = parseInt(wf.offsetWidth),
wf_width = parseInt((wf_boxWidth-((wf_len-1)*wf_space))/wf_len);
for(var i=0;i<wf_len;i++){ //循环
var column = document.createElement("div");
column.id = "column-"+i;
column.className = "column";
column.style.width = wf_width+"px";
column.style.cssFloat = "left";
column.style.styleFloat = "left"; //兼容IE
column.style.overflow = "hidden";
if(i===0){
column.style.marginLeft = 0;
}else{
column.style.marginLeft = wf_space+"px";
}
wf.appendChild(column);
for(var j=0;j<wf_data;j++){
var dom = document.getElementById("column-"+i);
var node=document.createElement("div");
node.style.marginBottom = wf_bottom+"px";
var img =Math.floor(Math.random()*5); //随机图片名称
node.innerHTML = '<img src="http://7u2sas.com1.z0.glb.clouddn.com/images/img'+img+'.jpg">'; //需要插入的内容,结构。可在css里控制样式
dom.appendChild(node);

}
}
}

</script>
</html>

h5的瀑布流的更多相关文章

  1. H5瀑布流如何实现

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  2. Jquery简单瀑布流代码示例

    最近很多网站都采用瀑布流风格设计,感觉挺有个性的,比较合适做图片类型的网站,没事仿开心网做一个瀑布流示例. 需要用到Jquery,jquery.masonry.min.js <!DOCTYPE ...

  3. 简单CSS定位瀑布流实现方法

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  4. 比较容易理解的---原生js瀑布流

    最近一直在恶补基础JS H5 CSS3的基础知识 关于这个瀑布流: 本来打算看着教程来做的. 不过 感觉理解起来有点复杂. SO, 自己参考教程默写了一个.. 目前我所接触过的瀑布流布局分为2大类 主 ...

  5. jQuery 实现的瀑布流

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"/> <title> ...

  6. jquery瀑布流的制作

    首先,还是来看一下炫酷的页面: 今天就边做边说了: 一.准备工作 新建css,js,img文件夹存放相应文件,并在demo.html文件中引入外部文件(注意要把jquery文件引入),这里就不过多描述 ...

  7. js瀑布流 原理实现揭秘 javascript 原生实现

    web,js瀑布流揭秘 瀑布流再很久之前流行,可能如我一样入行晚的 ,可能就没有机会去使用.但是这个技术终究是个挺炫酷的东西,花了一个上午来研究,用原生js实现了一个,下面会附上源码,供大家解读. 说 ...

  8. CollectionView水平和竖直瀑布流的实现

    最近在项目中需要实现一个水平的瀑布流(即每个Cell的高度是固定的,但是长度是不固定的),因为需要重写系统 UICollectionViewLayout中的一些方法通过计算去实现手动布局,所以本着代码 ...

  9. 用jquery实现瀑布流案例

    一.瀑布流是我们常见的案例,这里主要讲述,用jquery的方式实现瀑布流的功能! 引言:我们经常见到很多网站的瀑布流功能,如淘宝.京东这些商品等等.. 实现它我们首先考虑几个问题:1.获取到数据   ...

随机推荐

  1. jquery删除未来项 jquery on

    $(document).on('click', '.delbtn', function() { if (confirm("确定要删除吗?")) { var adminid=$(th ...

  2. Apache的最小配置

    以下配置是Apache的最小配置,路径为/usr/local/apache2/conf/include/lww.xhprof.conf <VirtualHost *:> ServerNam ...

  3. login/logout切换

    1. 前端按钮 <img border="0" width="18" height="18" src="<%=base ...

  4. sqlserver 批量修改表前缀

    先把第一句话放到sqlserver查询器中执行一下.然后把查询结果复制出来,进行编辑...一看你就懂了..简单的sql语句拼装 select ' exec sp_rename "' + na ...

  5. Android 获取 AudioRecord 麦克风音量大小并做选择性发送

    extends:http://blog.csdn.net/alvinhuai/article/details/8955127,http://mikespook.com/2010/11/android- ...

  6. iOS中的多线程基础

    NSThread NSThread是一个苹果封装过的,面向对象的线程对象.但是它的生命周期需要我们自己来手动管理,所以使用不是很常见,比如[NSThread currentThread],它可以获取当 ...

  7. Delphi XE2 生成的.exe 在未安装有Delphi的电脑上运行提示 “丢失 rtl160.bpl”

    解决方案: XE2中加入了多平台的概念,默认的Release模式,也是带包编译,带运行时库的,所以,需要手工设置一下工程选项: 打开工程以后,Project-->Options-->左侧树 ...

  8. string.IsNullOrWhiteSpace

    string.IsNullOrWhiteSpace(str) 这个是判断所有空白字符,功能相当于string.IsNullOrEmpty和str.Trim().Length总和,他将字符串给Char. ...

  9. 自定义switch开关

    自定义一个switch开关 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> ...

  10. php mysql 实现消息队列

    最近遇到一个批量发送短信的需求,短信接口是第三方提供的.刚开始想到,获取到手机号之后,循环调用接口发送不就可以了吗? 但很快发现问题:当短信数量很大时,不仅耗时,而且成功率很低. 于是想到,用PHP和 ...