首页 技术 正文
技术 2022年11月20日
0 收藏 653 点赞 3,514 浏览 2508 个字
<!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:0px;
padding:0px;
}
ul{
width:1080px;
margin: 100px auto 0;
}
li{
width:248px;
float:left;
border:1px solid pink;
list-style:none;
margin-right:10px;
}
li div {
border: 1px solid #000;
padding: 10px;
margin-bottom: 10px;
}
li div img {
width: 225px;
display: block;
}
</style>
<script>
window.onload = function ()
{
var oul = document.getElementById('ul1');
var ali = oul.getElementsByTagName('li');
var b = true;
var ipage = 1; getlist(); function getlist()
{
ajax('get','ajax pbl.php','cpage='+ipage,function (data)
{
var data = JSON.parse(data);
if(!(data.length))
{
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);
} b = true;
}); }
window.onscroll = function ()
{
var _index = getshort();
var oli = ali[_index]; var scrollTop = document.body.scrollTop || document.documentElement.scrollTop; if(gettop(oli)+oli.offsetHeight < document.documentElement.clientHeight + scrollTop)
{
if(b)
{
b = false;
ipage++;
getlist();
}
}
} function getshort()
{
var index = 0;
var ih = ali[index].offsetHeight; for(var i = 1; i < ali.length; i++)
{
if(ali[i].offsetHeight < ih )
{
index = i;
ih = ali[index].offsetHeight;
}
}
return index;
} function gettop(obj)
{
var itop = 0;
while(obj)
{
itop +=obj.offsetTop;
obj = obj.offsetParent;
}
return itop;
} 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);
}
}
}
}}
</script>
</head><body><ul id="ul1">
<li></li>
<li></li>
<li></li>
<li></li></ul>
</body>
</html>
<?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;?>
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,022
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,513
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,359
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,142
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,773
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,851