基于jQuery实现瀑布流页面

 更新时间:2017年04月11日 16:11:38   作者:失落的黎明  
这篇文章主要为大家详细介绍了基于jQuery实现瀑布流页面的相关资料,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

本文实例为大家分享了jQuery实现瀑布流页面展示的具体代码,供大家参考,具体内容如下

views.py

from django.shortcuts import render,HttpResponse
from app01 import models
import json
# Create your views here.
def index(req):
  if req.method == 'POST':
    dic = models.Upload.objects.filter(status=1).values('img1','name','info')
    dic = list(dic)
    dic = json.dumps(dic)
    print(dic)
    return HttpResponse(dic)
  return render(req, 'index.html')

url.py

from django.conf.urls import url
from django.contrib import admin
from app01 import views
urlpatterns = [
  url(r'^admin/', admin.site.urls),
  url(r'^index/', views.index),
]

index.html

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
  <style>
    .clearfix:after{
      content: '.';
      visibility: hidden;
      height: 0;
      clear: both;
      display: block;
    }
    img{
      width: 245px;
      height: 200px;
    }
  </style>
</head>
<body>
  <div id="container" style="margin: 0 auto;width: 980px;" class="clearfix">

    <div style="width: 245px;float: left">

    </div>

    <div style="width: 245px;float: left">

    </div>

    <div style="width: 245px;float: left">


    </div>

    <div style="width: 245px;float: left">


    </div>
  </div>
  <script src="/static/js/jquery-2.1.4.min.js"></script>
  <script>
    $(function () {
      $.ajax({
        url:'/index/',
        type:'POST',
        dataType:'json',
        success:function (arg) {
          $.each(arg, function (k, v) {
            console.log(k,v);
            k = k + 1;
            var div = document.createElement('div');
            div.className = 'c1';
            var img = document.createElement('img');
            img.src = "/" + v.img1;
            var p = document.createElement('p');
            p.innerText = v.info;
            div.appendChild(img);
            div.appendChild(p);
            if (k % 4 == 1) {
              $('#container').children(':eq(0)').append(div);
            } else if (k % 4 == 2) {
              $('#container').children(':eq(1)').append(div);
            } else if (k % 4 == 3) {
              $('#container').children(':eq(2)').append(div);
            } else if (k % 4 == 0) {
              $('#container').children(':eq(3)').append(div);
            } else {

            }
          })
         }
      })
    })


  </script>
</body>
</html>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

相关文章

  • 实现placeholder效果的方案汇总

    实现placeholder效果的方案汇总

    由于placeholder是html5的新属性,可想而知,仅支持html5的浏览器才支持placeholder,目前最新的firefox、chrome、safari以及ie10都支持,ie6到ie9都不支持。
    2015-06-06
  • jquery ajax post提交数据乱码

    jquery ajax post提交数据乱码

    今天发现在使用jquery ajax.post提交数据时会发现数据在ff正常,但在chrome与ie浏览器中post过去的数据全部是乱码
    2013-11-11
  • jquery 事件冒泡的介绍以及如何阻止事件冒泡

    jquery 事件冒泡的介绍以及如何阻止事件冒泡

    在一个对象上触发某类事件(比如单击onclick事件),如果此对象定义了此事件的处理程序,那么此事件就会调用这个处理程序,如果没有定义此事件处理程序或者事件返回true,那么这个事件会向这个对象的父级对象传播,从里到外,直至它被处理,挺起来感觉这么不可思议,接下来为大家解除疑惑
    2012-12-12
  • jquery插件EasyUI中form表单提交实例分享

    jquery插件EasyUI中form表单提交实例分享

    这篇文章主要介绍了jquery插件EasyUI中form表单提交实例,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2016-01-01
  • jQuery.position()方法获取不到值的安全替换方法

    jQuery.position()方法获取不到值的安全替换方法

    这篇文章主要介绍了jQuery.position()方法获取不到值的安全替换方法,本文给出了一种变通的方法,用.offset()来换算,需要的朋友可以参考下
    2015-03-03
  • 详解Jquery实现ready和bind事件

    详解Jquery实现ready和bind事件

    这篇文章主要为大家详细介绍了Jquery实现ready和bind事件的相关资料,感兴趣的小伙伴们可以参考一下
    2016-04-04
  • JQuery控制DIV的选取实现方法

    JQuery控制DIV的选取实现方法

    下面小编就为大家带来一篇JQuery控制DIV的选取实现方法。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2016-09-09
  • jQuery获得指定元素坐标的方法

    jQuery获得指定元素坐标的方法

    这篇文章主要介绍了jQuery获得指定元素坐标的方法,涉及offset().left及offset().top属性获取元素坐标的技巧,非常具有实用价值,需要的朋友可以参考下
    2015-04-04
  • jquery实现图片左右切换的方法

    jquery实现图片左右切换的方法

    这篇文章主要介绍了jquery实现图片左右切换的方法,设计jQuery操作页面元素及对应样式的相关技巧,具有一定参考借鉴价值,需要的朋友可以参考下
    2015-05-05
  • jQuery的控件及事件(输入控件及回车事件)使用示例

    jQuery的控件及事件(输入控件及回车事件)使用示例

    本文为大家介绍下jQuery的输入控件及回车事件的应用,具体示例代码如下,感兴趣的朋友可以参考下哈,希望对大家有所帮助
    2013-07-07

最新评论