瀑布流效果已经成为展示类型网站的首选,所以有必要掌握其实现过程。实现这个效果目前有三种方法,分别为:JavaScript原生方法、jQuery方法、CSS3多栏布局。
一、其中JavaScript方法就不多总结了,JQuery方法可以大大简洁JavaScript代码量。直接上jQuery代码
<pre name="code" class="html"><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>瀑布流</title>
<style type="text/css">
* {
margin: 0;
padding: 0;
}
article {
position: relative;
margin: auto 40px;
width: 100%;
}
article .box {
position: relative;
float: left;
}
article .box .content {
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px;
}
article .box .content img {
width: 280px;
height: auto;
}
</style>
</head>
<body>
<article>
<div class="box">
<div class="content">
<img src="images/1.jpg">
</div>
</div>
<div class="box">
<div class="content">
<img src="images/2.jpg">
</div>
</div>
<div class="box">
<div class="content">
<img src="images/3.jpg">
</div>
</div>
<div class="box">
<div class="content">
<img src="images/4.jpg">
</div>
</div>
<div class="box">
<div class="content">
<img src="images/5.jpg">
</div>
</div>
<div class="box">
<div class="content">
<img src="images/6.jpg">
</div>
</div>
<div class="box">
<div class="content">
<img src="images/7.jpg">
</div>
</div>
<div class="box">
<div class="content">
<img src="images/8.jpg">
</div>
</div>
<div class="box">
<div class="content">
<img src="images/1.jpg">
</div>
</div>
<div class="box">
<div class="content">
<img src="images/2.jpg">
</div>
</div>
<div class="box">
<div class="content">
<img src="images/3.jpg">
</div>
</div>
<div class="box">
<div class="content">
<img src="images/4.jpg">
</div>
</div>
<div class="box">
<div class="content">
<img src="images/5.jpg">
</div>
</div>
<div class="box">
<div class="content">
<img src="images/6.jpg">
</div>
</div>
<div class="box">
<div class="content">
<img src="images/7.jpg">
</div>
<