javascript--瀑布流客厅笔记

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>

瀑布流

</title>
    <style>
        *{
            font-size: 12px;
        }
        .bar{
            margin: 5px auto;
            width: 1016px;
            height: 20px;
            border: 1px solid #000;
        }
        #process{
            width: 10%;
            height: 100%;
            background-color: #ff0000;
        }
        .flow{
            margin: auto;
            width: 1016px;
            position: relative;
            border: 1px solid #000;
            height: 2500px;
        }
        .flow img{
            width: 250px;
        }
        .box{
            position: absolute;
            overflow: hidden;
            width: 250px;
            box-shadow: 0 1px 2px 0 rgba(180,180,180,.5);
            background: #fff;
            border-radius: 2px;
        }
        .box img{
            width: 250px;
            height: auto;
        }
        .box img:hover{
            opacity: 0.8;
            filter: alpha(opacity=80);
        }
        .message {
            margin: 0px 10px 11px;
            padding-top: 11px;
            overflow: hidden;
            height: 18px;
            color: #444;
            line-height: 18px;
        }
        .message label{
            color:#999;
        }
        .message a{
            height: 18px;
            color: #444;
            text-decoration: none;
            padding: 0 4px;
            display: inline-block;
            zoom: 1;
            border-radius: 2px;
            background-color: #f2f2f2;
            margin-right: 8px;
        }
        .message a:hover{
            color: #fff;
            background-color: #e5461c;;
        }
    </style>
    <script>
        var tags=["甜素纯","车模","长腿美女","街拍","时尚","写真","小清新",
                 "清纯","学生妹","唯美","甜美","萝莉","女仆装","兔女郎"];
        var lefts=[0+2,251+4,251*2+6,251*3+8];
        var tops =[0+2,0+2,0+2,0+2];
        var boxs =[];
        var imageCount=0;

//图片加载完成计数
        function fnCountImage(){
            imageCount++;

var process = document.getElementById("process");
            var p = 100*imageCount/35;
            process.style.width= p.toFixed(0)+"%";

if(imageCount==35){
                fnInit();
            }
        }

function fnLoadImage(){
            for(var i=1;i<=35;i++) {
                var box = fnCreateImageBox(i);
                boxs.push(box);
            }
        }

//初始化图片的定位
        function fnInit(){
            for(var i=0;i<boxs.length;i++){
                var box = boxs[i];
                if(i<4){
                    //定位
                    box.style.left=lefts[i]+"px";
                    box.style.top=tops[i]+"px";

//修改列的高度
                    tops[i]+=box.offsetHeight+2;
                }else{
                    //找最短的高度
                    //var minHeight = Math.min(tops[0],tops[1],tops[2],tops[3]);
                    var minHeight = Math.min.apply(null,tops);

//找最短的高度所在的列
                    var index = 0;
                    for(var j=0;j<tops.length;j++){
                        if(minHeight==tops[j]){
                            index=j;
                            break;
                        }
                    }

//定位
                    box.style.left=lefts[index]+"px";
                    box.style.top=tops[index]+"px";

//修改列的高度
                    tops[index]+=box.offsetHeight+2;
                }
            }
        }

function fnCreateImageBox(imgNO){
            /*
            <div class="box">
                <img src="pic/p01.jpg"/>
                <p class="message">
                    <label>标签:</label>
                    <a href="#">甜素纯</a>
                    <a href="#">车模</a>
                    <a href="#">长腿美女</a>
                </p>
            </div>
            */
            var div = document.createElement("div");
            div.className="box";

var img = document.createElement("img");
            var imgNO = imgNO<10 ? ("0"+imgNO) : imgNO;
            img.setAttribute("src","pic/p"+imgNO+".jpg");
            img.onload = fnCountImage;
            div.appendChild(img);

var p = document.createElement("p");
            p.className="message";
            div.appendChild(p);

var label = document.createElement("label");
            label.appendChild(document.createTextNode("标签:"));
            p.appendChild(label);

var count = fnRand(1,4);
            for(var i=0;i<count;i++){
                var a = document.createElement("a");
                a.setAttribute("href","javascript:void(0)");
                var text = tags[fnRand(0,tags.length-1)];
                a.appendChild(document.createTextNode(text));
                p.appendChild(a);
            }

document.getElementById("pics").appendChild(div);
            return div;
        }
        function fnRand(min,max){
            return Math.floor(Math.random()*(max-min+1))+min;
        }

window. fnLoadImage;
    </script>

</head>
<body>
    <div class="bar"><div id="process"></div></div>
    <div id="pics" class="flow"></div>
</body>
</html>

				
时间: 2024-11-24 02:09:55

javascript--瀑布流客厅笔记的相关文章

javascript瀑布流代码实例

javascript瀑布流代码实例:现在瀑布流效果大行其道,各种网站都有应用,尤其是专业的图片类型的网站,本站在特效下载专区也有此应用,当然实现此效果的方法有多种,下面是一段瀑布流代码实例供大家参考. <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title&

javascript瀑布流效果

<!doctype html> <html lang="en">  <head>   <meta charset="utf-8">   <title>瀑布流演示</title>   <link rel="stylesheet" type="text/css" href="pubu_css.css"/>   <scrip

javascript瀑布流

<!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <title>哇,瀑布流啊</title> <style type="text/css"> @media screen and (min-width:1550px){ .waterfall-container { width:1400px; } } @media screen a

MJ瀑布流学习笔记

1. 如果系统自带的布局的话,是这样: //系统自带的UICollectionViewFlowLayout 而不是UICollectionViewLayout UICollectionViewFlowLayout *waterLayout = [[UICollectionViewFlowLayout alloc]init]; waterLayout.itemSize = CGSizeMake(100, 300); waterLayout.minimumLineSpacing = 5; water

瀑布流 结合 懒加载 操作实例

<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta name="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0,user-scal

用JavaScript和jQuery实现瀑布流

▓▓▓▓▓▓ 大致介绍 在慕课网上学习了用原生js和jQuery实现瀑布流,在这里做个笔记 ▓▓▓▓▓▓ 用JavaScript实现 基本结构: <div id="main"> <div class="box"> <div class="pic"><img src="images/1.jpg" alt=""></div> </div>

Javascript之瀑布流(一)

哇,瀑布流,是的,不错,不错,真的不错,很好玩的样子,于是自己想玩玩啊,来吧,就玩起. 循序渐进,我这里采用原生的js代码来书写.为了方便大家运行代码,我就全部样式和CSS都写在html里面了,当然还需要图片,我会打包. 来上代码. 直接代码 <!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <title>哇,瀑布流啊</title> <style ty

javascript自适应宽度的瀑布流实现思路

这里主要介绍瀑布流的一种实现方法:绝对定位(css)+javascript+ajax+json.简单一点如果不做滚动加载的话就是绝对定位(css)+javascript了,ajax和json是滚动加载更多内容的时候用到的,感兴趣的你可以参考下哦 这样的布局并不陌生,从2011年Pinterest创立以来,中国互联网就迅速掀起了一股模仿Pinterest的热潮,国内有众多网站采用瀑布流的布局方式,例如花瓣网.美丽说等等.而事实上在中国互联网,模仿一些在国外被人看好的模式(当然,你也可以说是山寨或抄

javascript 简单的瀑布流

刚开始接触js,就想写写经典的瀑布流,搜了下网上的教程,发现大多是用jquery写的,非常简单,用它也不用考虑兼容性的问题(jquery已经考虑到了),就想自己用原生的js写个简单的瀑布流模型,暂且没有考虑到拖动时自动排版的情形,以后再添加.(发现用原生的js果然步骤比较多啊!很多方法都很底层的!) <!DOCTYPE HTML> <html> <head> <meta http-equiv="content-type" content=&qu