【js】 流式布局 页面
2015-07-07 21:13
579 查看
<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<meta charset="utf-8" />
<style type="text/css">
.eblock{ position: absolute;width:200px;min-height:300px; border:1px solid #F00;}
</style>
<script src="http://r.ytrss.com/rs/js/yintaih5/h5js/lib/jquery.js"></script>
<script type="text/javascript">
$(function() {
var current;
var rowfirst;
var rowsecond;
var rowthrid;
var rowfourth;
var index = 1;
$(".eblock").each(function() {
current = $(this);
// 获取首行元素
if (index <= 4) {
if (index % 4 == 1) {
rowfirst = $(this);
} else if (index % 4 == 2) {
rowsecond = $(this);
} else if (index % 4 == 3) {
rowthrid = $(this);
} else if (index % 4 == 0) {
rowfourth = $(this);
}
}
if (index > 4) {
if (index % 4 == 1) {
current.css("top", rowfirst.position().top + rowfirst.height() + 10 + "px");
current.css("left", rowfirst.position().left + "px");
rowfirst = $(this);
} else if (index % 4 == 2) {
current.css("top", rowsecond.position().top + rowsecond.height() + 10 + "px");
current.css("left", rowsecond.position().left + "px");
rowsecond = $(this);
} else if (index % 4 == 3) {
current.css("top", rowthrid.position().top + rowthrid.height() + 10 + "px");
current.css("left", rowthrid.position().left + "px");
rowthrid = $(this);
} else if (index % 4 == 0) {
current.css("top", rowfourth.position().top + rowfourth.height() + 10 + "px");
current.css("left", rowfourth.position().left + "px");
rowfourth = $(this);
}
}
index++;
});
});
//$(function() {
// $(".eblock").each(function() {
// alert($(this).css("height"));});
//});
</script>
</head>
<body style="margin: 0 auto; margin:0">
<div style="border:1px solid #F00; top: 200px; left: 240px;" class="eblock">fdgxcv
</div>
<div style=" border:1px solid #F00; top: 200px; left: 500px;" class="eblock"> xcvxcvxv
</div>
<div style=" border:1px solid #F00; top: 200px; left: 760px;" class="eblock"> xcvxcvxv
</div>
<div style=" border:1px solid #F00; top: 200px; left: 1020px;" class="eblock"> xcvxcvxv
</div>
<div class="eblock">
</div>
<div class="eblock"> 22
</div>
<div class="eblock">23
</div>
<div class="eblock"> 24
</div>
<div class="eblock"> 31
</div>
<div class="eblock"> 32
</div>
<div class="eblock"> xcvxcvxv
</div>
<div class="eblock"> xcvxcvxv
</div>
</body>
</html>
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<meta charset="utf-8" />
<style type="text/css">
.eblock{ position: absolute;width:200px;min-height:300px; border:1px solid #F00;}
</style>
<script src="http://r.ytrss.com/rs/js/yintaih5/h5js/lib/jquery.js"></script>
<script type="text/javascript">
$(function() {
var current;
var rowfirst;
var rowsecond;
var rowthrid;
var rowfourth;
var index = 1;
$(".eblock").each(function() {
current = $(this);
// 获取首行元素
if (index <= 4) {
if (index % 4 == 1) {
rowfirst = $(this);
} else if (index % 4 == 2) {
rowsecond = $(this);
} else if (index % 4 == 3) {
rowthrid = $(this);
} else if (index % 4 == 0) {
rowfourth = $(this);
}
}
if (index > 4) {
if (index % 4 == 1) {
current.css("top", rowfirst.position().top + rowfirst.height() + 10 + "px");
current.css("left", rowfirst.position().left + "px");
rowfirst = $(this);
} else if (index % 4 == 2) {
current.css("top", rowsecond.position().top + rowsecond.height() + 10 + "px");
current.css("left", rowsecond.position().left + "px");
rowsecond = $(this);
} else if (index % 4 == 3) {
current.css("top", rowthrid.position().top + rowthrid.height() + 10 + "px");
current.css("left", rowthrid.position().left + "px");
rowthrid = $(this);
} else if (index % 4 == 0) {
current.css("top", rowfourth.position().top + rowfourth.height() + 10 + "px");
current.css("left", rowfourth.position().left + "px");
rowfourth = $(this);
}
}
index++;
});
});
//$(function() {
// $(".eblock").each(function() {
// alert($(this).css("height"));});
//});
</script>
</head>
<body style="margin: 0 auto; margin:0">
<div style="border:1px solid #F00; top: 200px; left: 240px;" class="eblock">fdgxcv
</div>
<div style=" border:1px solid #F00; top: 200px; left: 500px;" class="eblock"> xcvxcvxv
</div>
<div style=" border:1px solid #F00; top: 200px; left: 760px;" class="eblock"> xcvxcvxv
</div>
<div style=" border:1px solid #F00; top: 200px; left: 1020px;" class="eblock"> xcvxcvxv
</div>
<div class="eblock">
</div>
<div class="eblock"> 22
</div>
<div class="eblock">23
</div>
<div class="eblock"> 24
</div>
<div class="eblock"> 31
</div>
<div class="eblock"> 32
</div>
<div class="eblock"> xcvxcvxv
</div>
<div class="eblock"> xcvxcvxv
</div>
</body>
</html>
相关文章推荐
- Chrome控制台 JS调试的一些小技巧
- javascript内置顶层函数
- javascript数租
- js中的各种难题(1)
- javascript对文档对象的内容、属性、样式的操作
- JSP整理总结--9大内置对象、4个作用域
- JSon 简单例子
- JAWR【一个java项目的javascript和CSS集成和压缩工具】
- JSP整理总结--JSP指令、动作标签
- javascript笔记02:严格模式的特定要求
- JavaScript学习笔记
- 完美的js URLEncode函数
- js 增删改查
- 高性能javascript小结
- 枚举做JSP下拉选框的数据源
- 【转载】JavaScript 经典实例收集整理
- JavaScript之this用法详解
- js window对象
- 【翻译】使用Sencha Ext JS 6打造通用应用程序
- 【转载】理解 Javascript 中变量的作用域