用$.getJSON() 和$.post()获取第三方数据做页面 ——惠品折页面(1)
用$.getJSON() 和$.post()获取第三方数据做页面
首页 index.html 页面
需要jquery 和 template-web js文件 可以直接在官网下载
中间导航条的固定
可以在导航添加一个动态class值 class值 的css样式 position :fixed ;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="index.css">
<title>惠品折首页</title>
</head>
<body> <header>
<div id="top">
<img src="http://m.huipinzhe.com/static/img/logo.jpg" alt="logo">
<input type="text">
<a href="category.html" target="_self"><img src="./images/menu.png" alt="search"></a> </div>
</header>
<img id="banner" src="http://huipinzhe-img-03.b0.upaiyun.com/banner1009/梁荷750.png" alt="">
<img id="banner1" src="./images/banner.png" alt="">
<div id="mainMenuBarAnchor"></div>
<div id="mainMenuBar">
<ul id="ul"> </ul>
</div>
<div id="bottom">
<a href="index.html"><img src="data:images/home.png" alt=""></a>
<a href="specialList.html"><img src="data:images/juan.png" alt=""></a>
<a href="find.html"><img src="data:images/miao.png" alt=""></a>
<a><img src="data:images/my.png" alt=""> </a>
</div>
<section id="container"><section> <script id="goods" type="text/html">
{{each rows good }}
{{if good.itemType=="TIANMAO"}}
<div class="good">
<img src=" {{good.image}}">
<div>
<p><span>天猫</span>{{good.title}}</p>
<p class="zi">活动价¥{{good.phoneActivityPrice}} </p>
<p class="tu"><div>{{good.originPrice}}</div><div>立即抢购</div></p>
</div>
</div>
{{else if good.itemType=="TAOBAO"}}
<div class="good">
<img src=" {{good.image}}">
<div>
<p><span>淘宝</span>{{good.title}}</p>
<p class="zi">活动价¥{{good.phoneActivityPrice}} </p>
<p class="tu"><div>{{good.originPrice}}</div><div>立即抢购</div></p>
</div>
</div> {{/if}} {{/each}} </script>
<script src="jquery.js"></script>
<script src="template-web.js"></script>
<script src="index.js"></script>
</body>
</html>
首页css 样式 index.css
*{
box-sizing: border-box;
}
html{
height: 100%; }
body{
height: 100%;
margin:;
padding:;
background-color: gainsboro;
}
header{
background-color: white;
height: 8%;
position: fixed;
top:;
left:;
right:;
box-shadow: 0 0 10px gainsboro;
z-index:; }
#top{
display: flex;
align-items: center;
height: 100%;
/* background-color: red; */
position: relative;
}
#top >img:nth-child(1){
width: 140px;
margin-left: 20px; }
#bottom{
position: fixed;
bottom: 0px;
z-index:;
width: 100%;
height: 8%;
background-color: white;
display: flex;
justify-content: space-around;
}
#bottom>a{
display: inline-block;
height: 100%;
}
#bottom>a>img{
display: inline-block;
height: 100%;
}
#top>input{
margin-left: 30px;
border-color: gainsboro;
background-color: gainsboro;
height: 60%;
width:70%;
border:none;
border-radius: 35px;
} #top>img:nth-child(3){
width:80px;
height: 80%;
position: absolute;
right: 10px;
}
#banner{
/* display: block; */
margin-top: 13% ;
width: 100%;
margin-bottom: 15px;
}
#banner1{
/* margin-top: 13%; */
width: 100%;
}
#ul>li:first-child{
color:red;
border-bottom: 2px solid red;
}
#ul >li{ list-style: none;
display:inline-block;
color:black;
margin-left:50px;
font-size:30px;
font-weight:;
line-height: 80px;
}
#mainMenuBar{ width:100%;
white-space:nowrap ;
overflow-x: scroll;
background-color: white;
z-index:;
}
.stick {
border-top: 8px solid gainsboro;
margin-top: 13.5% ;
position:fixed;
top:;
}
#container{
height: 100%;
width:100%;
overflow: scroll;
}
.good{
width:100%;
font-size: 30px;
background-color: white;
padding-top:15px;
margin-bottom: 30px;
}
.good >img{
width: 40%;
display: inline-block;
}
.good>div{ display: inline-block;
width: 55%;
}
首页js文件 index.js
$.getJSON('http://m.huipinzhe.com/h5/home/gethomepage',function(data){
console.log(data);
$('#banner').attr('src',data.data.HomeModelList[0].rows[0].image);
var labels=data.data.labels;
console.log(labels);
for(var i=0;i<labels.length;i++){
$('#ul').append('<li class="'+labels[i].id+'">'+labels[i].label+'</li>');
} $(document).ready(function() {
var $window = $(window),
$mainMenuBar = $('#mainMenuBar'),
$mainMenuBarAnchor = $('#mainMenuBarAnchor');
$window.scroll(function() {
var window_top = $window.scrollTop();
var div_top = $mainMenuBarAnchor.offset().top;
if (window_top > div_top) {
$mainMenuBar.addClass('stick');
$mainMenuBarAnchor.height($mainMenuBar.height());
} else {
$mainMenuBar.removeClass('stick');
$mainMenuBarAnchor.height(0);
}
});
});
//初始值
//商品列表初始 clickTurn(-1);
//导航鼠标的点击事件
$('#ul>li').click(function(){
$(this).css({
color:'red',
'border-bottom': '2px solid red',
}).siblings().css({
color:'black',
'border-bottom':'none',
});
var labelId=$(this).attr('class');
//清空container中的内容 添加新的内容
// $('#container').empty();
clickTurn(labelId);
}); }); /* 推荐商品列表 */
function clickTurn(labelId){
var page=0;
var isFinsh;
function getDataByPageNumber(){
isFinsh=false;
page++;
if(page>12){
alert('已经加载完毕');
return;
}
$.post('http://m.huipinzhe.com/h5/home/gethomepage',{labelId : labelId ,pageNum : page},function(data){ console.log(data.data.onlineData);
var data=data.data.onlineData;
var html=template('goods',data);
$('#container').html(html);
isFinsh=true;
});
}
getDataByPageNumber();
$('#container').scroll(function(event){
console.log("滚动");
if(event.target.scrollTop+event.target.clientHeight>event.target.scrollHeight-10){
console.log('获取下一页数据');
if(isFinsh){
getDataByPageNumber();
}
}
});
}
用$.getJSON() 和$.post()获取第三方数据做页面 ——惠品折页面(1)的更多相关文章
- [ 转 ]jquery的ajax和getJson跨域获取json数据
目前浏览器端跨域访问常用的两种方法有两种: 1.通过jQuery的ajax进行跨域,这其实是采用的jsonp的方式来实现的. jsonp是英文json with padding的缩写.它允许在服务器端 ...
- jquery的ajax和getJson跨域获取json数据
目前浏览器端跨域访问常用的两种方法有两种: 1.通过jQuery的ajax进行跨域,这其实是采用的jsonp的方式来实现的. jsonp是英文json with padding的缩写.它允许在服务器端 ...
- 【CSS系列】获取实时数据做进度
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- ASP.NET框架获取数据字典数据做成树的格式
private List<TreeEntity> treeList = new List<TreeEntity>();//创建一个树的List集合 public ActionR ...
- jq:get获取json数据并以表格形式生成到页面
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- 使用$.getJSON("xx.json" ,function(data){ console.logy(data); })在本地获取 json数据
使用 $.getJSON() 在本地获取 json数据 默认在谷歌,火狐等其他浏览器,不允许在本地获取服务器数据 所以不能在本地中使用 但是可以IE 11 中又可以使用,所以,测试时建议在IE浏览器 ...
- 使用JSONP,jQuery的ajax跨域获取json数据
网上找了很多资料,写的不错,推荐下: 1.深入浅出JSONP--解决ajax跨域问题 (http://www.cnblogs.com/chopper/archive/2012/03/24/240394 ...
- JQuery 获取json数据$.getJSON方法的实例代码
这篇文章介绍了JQuery 获取json数据$.getJSON方法的实例代码,有需要的朋友可以参考一下 前台: function SelectProject() { var a = new Array ...
- $.getJSON获取json数据失败
首先简单介绍下 $.ajax $.get $.post $.getJSON 的区别和用法 $.ajax中有一个type属性,专门用来指定是get请求还是post请求的分别对应的就是$.get和$ ...
随机推荐
- 8.中断按键驱动程序之poll机制
本节继续在上一节中断按键程序里改进,添加poll机制. 那么我们为什么还需要poll机制呢.之前的测试程序是这样: ) { read(fd, &key_val, ); printf(" ...
- 【打死树莓派】-树莓派3代jessie+Opencv-解决安装不了libgtk2.0-dev包问题
按照国际法先贴问题 Some packages could not be installed. This may mean that you have requested an impossible ...
- Project 6:上楼梯问题
问题简述:梯有N阶,上楼可以一步上一阶,也可以一步上二阶.编写一个程序,计算共有多少中不同的走法. 样例输入: 5 样例输出: 8 #include <stdio.h> int count ...
- Unity2017.x 版本的下载安装
Unity2017 版本从2017年7月开始正式发布Unity2017.1版本,为了初学者更加清晰明了的掌握全过程,笔者还是以完整的共19个步骤来给大家演示下载与配置安装的全过程,方便广大读者的无障碍 ...
- IPsec_VPN实现技术【转载】
GRE Tunnel GRE Tunnel(General Routing Encapsulation 通用路由封装)是一种非常简单的VPN(Virtual Private Network 虚拟专用网 ...
- CentOS6.5下安装mfs分布式存储(转)
MFS文件系统的组成 1. 元数据服务器.在整个体系中负责管理管理文件系统,目前MFS只支持一个元数据服务器master,这是一个单点故障,需要一个性能稳定的服务器来充当.希望今后MFS能支持多个m ...
- 201521123091 《Java程序设计》第4周学习总结
Java 第二周总结 第四周的作业. 目录 1.本章学习总结 2.Java Q&A 3.使用码云管理Java代码 4.PTA实验 1.本章学习总结 1.1 尝试使用思维导图总结有关继承的知识点 ...
- 201521123078《Java程序设计》第七周学习总结
1. 本周学习总结 2. 书面作业 1.ArrayList代码分析 1.1 解释ArrayList的contains源代码 public boolean contains(Object o) { re ...
- java第二次实验
1. 本章学习总结 答:学会在java中使用函数调用. 学会在Java程序中使用函数,使程序层次更清晰. 使用StringBuilder代替string拼接,减少内存空间的占用. 使用BigDecim ...
- 201521123028 《Java程序设计》第2周学习总结
1. 本周学习总结 1.学习了String及部分函数用法,例如PTA上<5-2 jmu-Java-02基本语法-02-StringBuilder>一题中用到了"str.appen ...