先放一张效果图

这是我们的一个学期项目,开始我只想做这一个界面,后来又加了很多,但是我还是觉得这个网页比较纯粹,所以就拿出来了。
首先得说一下数据是从哪里的来的。
这里的数据全部来自BILIBILI的一个API
链接:https://api.bilibili.com/pgc/web/timeline/v2?season_type=1

然后我们的任务就很简单了,只要把数据从JSON中提取出来然后用合适的方式组织起来就好了
$.ajax({
type:"get", //使用get方式
url: "bilibili.json", //json文件相对于这个HTML的路径
dataType:"json",
success:function(data) {
var obj=data;
/*document.getElementById("out").innerHTML=obj.result.latest[0].title+"<br/>"+
obj.result.latest[0].pub_index+"<br/>";
//alert(obj.result.latest[0].square_cover);
document.getElementById("pic").src=obj.result.latest[0].square_cover;*/
var l=obj.result.latest.length;
for(var j=0;j<l;j++)
{
var p1=document.createElement("p");
p1.className="inline";
p1.innerHTML=obj.result.latest[j].title+" "+
obj.result.latest[j].pub_index
+"<a οnclick='trans("+obj.result.latest[j].season_id+")' class='linka'> </a>"
//+"<a οnclick='trans("+obj.result.latest[j].season_id+")' class='linka'> </a>";
//var but=document.createElement("a");
//a.innerHTML="▶";
//but.href="https://www.bilibili.com/bangumi/play/ss"+obj.result.latest[j].season_id;
var p2=document.createElement("img");
p2.src=obj.result.latest[j].square_cover;
p2.className="coin";
var div=document.createElement("div");
div.className="line";
document.getElementById("subline").appendChild(div);
div.appendChild(p2);
div.appendChild(p1);
//div.appendChild(but);
}
},
error:function() {
alert("请求失败");
}
});
这里用到的是jQuery的ajax,因为比较简单明了。因为涉及到get操作,所以需要有一个模拟的服务器环境(很多IDE都可以自动配置,但是记事本或者没有相应插件的vscode就不太行)
当然要达到我上图展示的那种效果需要配合一定的css样式,我的代码为了适应学期项目的要求进行了很多添改,我这里只放出最原始的部分
<!-- html -->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="content-type" />
<meta content="text/html" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<meta name="referrer" content="no-referrer">
<!-- https://api.bilibili.com/pgc/web/timeline/v2?season_type=1 Data come from-->
<script src="jquery-3.6.0.min.js" ></script>
<style>
.subline{
background-image: linear-gradient(#DFDFDF,#e0c1ff);
}
p.inline{
color:#E38D13;
display: inline;
margin: 1rem;
font-size: medium;
}
.coin{
width: 8rem;
height: 8rem;
}
.line{
margin: 0.5rem;
vertical-align: middle;
background-color: #66ccff50;
}
.linka{
display: inline;
float: right;
position: relative;
top: 2rem;
right: 4rem;
width: 3rem;
height: 3rem;
background-image: url(run_normal.png);
background-repeat: no-repeat;
}
.tech{
color: #22222250;
}
</style>
</head>
<body>
<title>bangumi schedule</title>
<div class="container" id="contain">
<div class="subline" id="subline">
<div id="constraint">
<iframe id="biliin" src="https://www.bilibili.com/bangumi/play/ss38260"
allowfullscreen="allowfullscreen" width="100%" height="550" scrolling="no" frameborder="0"
style="position: relative;top: -4rem;"
sandbox="allow-top-navigation allow-same-origin allow-forms allow-scripts"
></iframe>
</div>
</div>
</div>
function trans(sid)
{
document.getElementById("biliin").src="https://www.bilibili.com/bangumi/play/ss"+sid;
}
$.ajax({
type:"get", //使用get方式
url: "bilibili.json", //json文件相对于这个HTML的路径
dataType:"json",
success:function(data) {
var obj=data;
/*document.getElementById("out").innerHTML=obj.result.latest[0].title+"<br/>"+
obj.result.latest[0].pub_index+"<br/>";
//alert(obj.result.latest[0].square_cover);
document.getElementById("pic").src=obj.result.latest[0].square_cover;*/
var l=obj.result.latest.length;
for(var j=0;j<l;j++)
{
var p1=document.createElement("p");
p1.className="inline";
p1.innerHTML=obj.result.latest[j].title+" "+
obj.result.latest[j].pub_index
+"<a οnclick='trans("+obj.result.latest[j].season_id+")' class='linka'> </a>"
//+"<a οnclick='trans("+obj.result.latest[j].season_id+")' class='linka'> </a>";
//var but=document.createElement("a");
//a.innerHTML="▶";
//but.href="https://www.bilibili.com/bangumi/play/ss"+obj.result.latest[j].season_id;
var p2=document.createElement("img");
p2.src=obj.result.latest[j].square_cover;
p2.className="coin";
var div=document.createElement("div");
div.className="line";
document.getElementById("subline").appendChild(div);
div.appendChild(p2);
div.appendChild(p1);
//div.appendChild(but);
}
},
error:function() {
alert("请求失败");
}
});
2415




被折叠的 条评论
为什么被折叠?



