ajax 瀑布流 demo
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style>
body {margin: 0;}
#ul1 {width: 1080px; margin: 100px auto 0;}
li { width: 247px; list-style: none; float: left; margin-right: 10px; }
li div {border: 1px solid #000; padding: 10px; margin-bottom: 10px;}
li div img { width: 225px; display: block;}
</style>
<script src="ajax.js"></script>
<script>
window.onload = function(){
var oUl = document.getElementById('ul1');
var aLi = oUl.getElementsByTagName('li');
var iLen = aLi.length;
var ipage = 1;
var onOff = true;
getList(); function getList(){
ajax('get','getPics.php','cpage='+ipage,function(data){
var data = JSON.parse(data);
if(!data){
return;
}
for(var i=0;i<data.length;i++){
var _index = getShort();
var oDiv = document.createElement('div');
var oImg = document.createElement('img');
oImg.src = data[i].preview;
oImg.style.width = '225px';
oImg.style.height = data[i].height * ( 225 / data[i].width ) + 'px';
oDiv.appendChild(oImg);
var oP = document.createElement('p');
oP.innerHTML = data[i].title;
oDiv.appendChild(oP);
aLi[_index].appendChild(oDiv);
}
onOff = true;
});
} /*拉动滚动条触发*/
window.onscroll = function(){
var _index = getShort();
var oLi = aLi[_index];
var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
if(getTop(oLi)+oLi.offsetHeight < document.documentElement.clientHeight +scrollTop ){
if(onOff){
onOff = false;
ipage++;
getList();
}
}
};
/*获取元素top*/
function getTop(obj){
var iTop = 0;
while(obj){
iTop += obj.offsetTop;
obj = obj.offsetParent;
}
return iTop;
}
/*获取页面li的最短高度*/
function getShort(){
var index = 0;
var ih = aLi[index].offsetHeight;
for(var i=1;i<iLen;i++){
if(ih > aLi[i].offsetHeight){
index = i;
ih = aLi[index].offsetHeight;
}
}
return index;
}
};
</script>
</head> <body>
<ul id='ul1'>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</body>
</html>
function ajax(method, url, data, success) {
var xhr = null;
try {
xhr = new XMLHttpRequest();
} catch (e) {
xhr = new ActiveXObject('Microsoft.XMLHTTP');
}
if (method == 'get' && data) {
url += '?' + data;
}
xhr.open(method,url,true);
if (method == 'get') {
xhr.send();
} else {
xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
xhr.send(data);
}
xhr.onreadystatechange = function() {
if ( xhr.readyState == 4 ) {
if ( xhr.status == 200 ) {
success && success(xhr.responseText);
} else {
alert('出错了,Err:' + xhr.status);
}
}
}
}
<?php
header('Content-type:text/html; charset="utf-8"'); /*
API:
getPics.php 参数
cpage : 获取数据的页数
*/
$cpage = isset($_GET['cpage']) ? $_GET['cpage'] : 1; $url = 'http://www.wookmark.com/api/json/popular?page=' . $cpage; $content = file_get_contents($url);
$content = iconv('gbk', 'utf-8', $content); //echo $content; ?>
ajax 瀑布流 demo的更多相关文章
- 原生ajax瀑布流demo
最近听朋友们说起瀑布流挺多的,自己就去研究下了,一个简单的原生demo,分享给大家... 简单分为三个文档,有详细的注释:img:ajax.php:demo.php 其中img文件夹中放入图片 1.j ...
- Ajax——瀑布流
基本概念 1.宽度是一致的,高度上参差不齐 2.新增内容优先放置在最矮的地方 核心难点 1.用一个数组存储每列的高度值 2.新值添加到值最小索引上,每次替换更新数组 插件使用 1.$.fn.exten ...
- Hawk 3.1 动态页面,ajax,瀑布流
不少朋友反映,Hawk的手气不错,好像没法处理动态页面.其实很容易,比其他软件都容易,让我慢慢道来. 1. 什么是动态页面 很多网站,在刷新的时候会返回页面的全部内容,但实际上只需要更新一部分,这样可 ...
- ajax 瀑布流实现
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- jQuery ajax瀑布流加载静态的列表页面
1.加载一行数据 <script> //滚动加载事件 var Loadurl = "{$url}"; if(window.location.href !== Loadu ...
- iOS 瀑布流的Demo
/** * 瀑布流Demo的主要代码,若想看完整的代码请到下面链接去下载 * * 链接: https://pan.baidu.com/s/1slByAHB 密码: r3q6 */ #import &l ...
- js原生瀑布流
背景: 1.在移动端开发,jq文件是显得非常庞大的,所以所有效果尽量用HTML5和原生js实现. 2.本次瀑布流是固定列数,采用非浮动的另外一种瀑布流思想实现的. 3.本次数据来源是json接口 4. ...
- 瀑布流原生ajax,demo
最近听朋友们说起瀑布流挺多的,自己就去研究下了,一个简单的原生demo,分享给大家... 简单分为三个文档,有详细的注释 img:ajax.php:demo.php 其中img中放入图片 1.jpg: ...
- 瀑布流AJAX无刷新加载数据列表--当页面滚动到Id时再继续加载数据
瀑布流加载显示数据,在当下已经用的很普遍,尤其是我们在做网上商城时,在产品列表页面已经被普遍使用. 对于实现瀑布流布局的解决方案主要有以下两种方式: 1.对每一条显示数据使用绝对定位+浮动的方式,这样 ...
随机推荐
- linux一些基本操作-防火墙操作
防火墙操作 一.service方式 查看防火墙状态: [root@centos6 ~]# service iptables status iptables:未运行防火墙. 开启防火墙: [root@c ...
- 二评北科团委:“斩首计划”进行时,其用心也毒
近日,在同学们和热心群众的共同努力下,各高校相继悬崖勒马,北大马会.北语新新青年.人大新光等进步社团均顺利注册.而北科团委倒行逆施,可谓一枝独秀,对于齐民学社的同学们的诉求,不仅不予以回应,反而采取表 ...
- [LC] 209. Minimum Size Subarray Sum
Given an array of n positive integers and a positive integer s, find the minimal length of a contigu ...
- 如何模拟ip
展开全部回答查看 https://segmentfault.com/q/1010000002990136 模拟国外ip https://gtmetrix.com/ 登录后才可以切换模拟的地区
- Qt QString与string的转换
QString --> string QString.toStdString(); string --> QString QString::fromStdString(string);
- 关于使用css变量实现主题的切换效果
现在要实现网页主题的切换成本较小的一种方案就是使用css的变量来实现 HTML 在HTML的body标签上先定义一个id元素属性 <body id="sm-theme"> ...
- First Django app(各个文件以及文件夹解析)
mkdir mysite cd mysite django-admin.py startproject mysite 执行上面的命令,得到一下内容: mysite/ manage.py mysite/ ...
- win7+centos6.5安装双系统
前言:之前在琢磨怎么安装双系统 倒腾了两天终于给装上了 使用软件 镜像:CentOS-6.5-x86_64-bin-DVD1.iso 开机引导软件 easybcd2.2 u盘制作软件 USBWrite ...
- Nginx笔记总结十一:Nginx重写规则指南
依赖PCRE库,需要安装pcre,最多循环10次,超过后返回500错误, 1. rewrite模块指令 break:完成当前设置的重写规则,停止执行其他的重写规则 if: if () { ...
- 吴裕雄--天生自然KITTEN编程:行走