waterfull效果

views:

def pubuliu(request):
    return render(request,"瀑布流.html")


def loadimgs(request):
    col = request.GET.get("col")
    col = int(col)
    objs = models.Imgs.objects.values("img_path","title","content")[col:col+8]
    objs = list(objs)
    print(col)
    ret={
        "status":"OK,这是一个测试",
        "data":objs
    }
   # print(objs)
    return HttpResponse(json.dumps(ret))

HTML:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>瀑布流</title>
    <style>
        #w{
            width: 100%;
        }
        .cols{
            width: 25%;
            float: left;
        }
        .cols img{
            width: 100%;
        }
    </style>
</head>
<body>
<div id="w">
    <div class="cols">   123
    </div>
    <div class="cols">      sasdf
    </div>
    <div class="cols">      we
    </div>
    <div class="cols">       ad
    </div>

</div>

</body>
    <script src="/static/jquery-3.3.1.min.js"></script>
    <script>
        $(function(){
            loadimg();
            reloadimg();
        })
        positionNow = 0;
        function loadimg(){
            tempcol = 0;
            $.ajax({
                url:"/loadimgs/",
                data:{"col":positionNow},
                type:"GET",
                dataType:"JSON",
                success:function(args){
                    console.log(args.status);
                    positionNow+=8;
                    $.each(args.data,function (i,v) {
                        imgs = document.createElement("img");
                        imgs.src="/"+v["img_path"];
                        tempcol=i%4;
                        $("#w").children().eq(tempcol).append(imgs);
                        console.log(i,v);
                    })
                    console.log($("#w").children().eq(0).html())
                }
            })
        }
        function reloadimg() {
            $(window).scroll(function(){
                console.log(123)
                //窗口高度 $(window).scrollTop()
                //滑轮剩余高度 $(document).height()
                //文本总高度 $(window).scrollTop()
                if($(document).height()==$(window).height()+$(window).scrollTop()){
                    loadimg();
                }
            })
        }
    </script>
</html>

models.Imgs:

class Imgs(models.Model):
    img_path = models.ImageField(upload_to="static/imgs")
    title = models.CharField(max_length=128)
    content = models.CharField(max_length=128)

django mysql数据库配置

settings.py:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'pubuliu',
        'USER':'root',
        'PASSWORD':'123',
        'HOST':'127.0.0.1',
        'PORT':'3306',
    }
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值