zoukankan      html  css  js  c++  java
  • ajax加载瀑布流

    <div class="warp" id="warp">
    <ul>
    <li></li>
    <li style="margin: 0 22px;"></li>
    <li></li>
    </ul>
    <div class="" style="clear: both"></div>
    <button id="btn" class="btn">加载更多</button>
    </div>
    var oLi=document.getElementsByTagName('li');
            var btn=document.getElementById('btn');
            var num=3;
            load(num);
            btn.onclick=function(){
                num+=3;
                load(num);
            }
            function load(num){
                $.ajax({
                    type:'get',
                    url:'data.php',
                    success:function(res){
                        res=eval('('+res+')');
                        //alert(res);
                        for(var i=num;i<num+6;i++)
                        {
                            var src=res[i].src;
                            var title=res[i].title;
                            var oImg=new Image();
                            oImg.src=src;
                            oImg.onload=function(){
                                oDiv=document.createElement('div');
                                oA=document.createElement('a');
                                oP=document.createElement('p');
                                oDiv.className='con',
                                oA.href='javascript:void(0);',
                                oA.innerHTML=title,
                                oP.innerHTML='阅读全文',
                                oDiv.appendChild(this);
                                oDiv.appendChild(oA);
                                oDiv.appendChild(oP);
                                oLi[getShort()].appendChild(oDiv);
                            }
                        }
                    },
                });
            }
            function getShort(){
                var index=0;
                var iH=oLi[index].offsetHeight;
                for(var i=0;i<oLi.length;i++)
                {
                    if(oLi[i].offsetHeight<iH)
                    {
                        index=i;
                        iH=oLi[index].offsetHeight;
                    }
                }
                return index;
            }
  • 相关阅读:
    遗传算法求解旅行商(TSP)问题 -- python
    office 小技巧
    oracle创建dblink
    c# equals与==的区别
    两人之间的一些参数
    .net 枚举(Enum)使用总结
    SQL Server 日期的加减函数: DATEDIFF DATEADD
    jquery操作select
    AS3帮助手册
    Razor和HtmlHelper的使用意义
  • 原文地址:https://www.cnblogs.com/xiecheng/p/5616702.html
Copyright © 2011-2022 走看看