apiCloud中实现头部与内容分离与操作规范,App头部header固定,头部与内容分离
官方案例
1.头部拆分成一个页面比如news-text
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0,user-scalable=0, width=device-width"/>
<title>api</title>
<link rel="stylesheet" type="text/css" href="../css/api.css" />
<link rel="stylesheet" type="text/css" href="../css/common.css" />
<link rel="stylesheet" type="text/css" href="../css/news-text.css" />
</head>
<body>
<div id="wrap">
<div id="header">
<a class="back-icon" tapmode="" onclick="api.closeWin()"></a>
<h1>热点新闻</h1>
</div>
</div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/news-text.js"></script>
</html>
2.内容拆分成另一个页面比如news-textCon
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0,user-scalable=0, width=device-width"/>
<title>api</title>
<link rel="stylesheet" type="text/css" href="../css/api.css" />
<link rel="stylesheet" type="text/css" href="../css/common.css" />
<link rel="stylesheet" type="text/css" href="../css/news-text.css" />
</head>
<body>
<div id="wrap">
<div id="main">
<script id="news-template" type="text/x-dot-template">
<h1>{{=it.title}}</h1>
<label>
{{? it.from }}
{{=it.from}}
{{?}}
<em>{{=it.date}}</em>
</label>
<div id="summary">
{{=it.summary}}
</div>
<div>
{{=it.content}}
</div>
<a id="fav" class="btn" tapmode="active" news-id="{{=it.id}}" >收藏</a>
</script>
<div id="content"></div>
</div>
</div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<script type="text/javascript" src="../script/doT.min.js"></script>
<script type="text/javascript" src="../script/zepto.js"></script>
<script type="text/javascript" src="../script/news-textCon.js"></script>
</html>
以上就是一个非常规范的内容
1.css在头部
引入必要的css,api.css
引入通用的css,common.css
引入页面特有的css,news-text.css
2.js在尾部
引入必要的css,api.js
引入通用的css,common.js
引入页面特有的css,news-text.js
根据页面需要,引入doT模板和zepto(手机端的jQuery替代品)
来看看news-text.js中的内容
apiready = function(){
var header = $api.byId('header'); // 获取头部
$api.fixStatusBar(header); // 处理ios兼容
var newsId = api.pageParam.newsId; // 获取参数
var pos = $api.offset(header); // 获取位置数据
api.openFrame({ // 打开Frame
name: 'news-textCon',
url: 'news-textCon.html',
pageParam: {newsId: newsId}, // 传递参数
rect:{
x: 0,
y: pos.h, // 头部留位置
w: 'auto',
h: 'auto'
},
bounces: true,
vScrollBarEnabled: false
});
};
打开frame,保证头部留有位置,同时可以传递参数
再看看news-textCon.js中的内容
apiready = function () {
var newsId = api.pageParam.newsId; // 获取参数
var getNewsByIdUrl = '/news/?filter=';
var urlParam = {where: {id: newsId}};
api.showProgress({
title: '加载中...',
modal: false
});
ajaxRequest(getNewsByIdUrl+JSON.stringify(urlParam),'get','',function(ret,err){
if (ret) {
api.toast({
...
})
} else {
api.toast({
...
})
}
api.hideProgress();
});
};
获取传入的参数,
获取数据与相应的页面处理
我的案例
商品详情拆分
1.goods_detail.html
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0,user-scalable=0, width=device-width"/>
<title>api</title>
<link rel="stylesheet" type="text/css" href="../css/api.css" />
<link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
</head>
<body>
<div id="wrap">
<div id="main">
<header class="aui-bar aui-bar-nav fix-status-bar" id="aui-header">
<a class="aui-btn aui-pull-left" tapmode onclick="api.closeWin();">
<span class="aui-iconfont aui-icon-left"></span>
</a>
<div class="aui-title"><!-- 商品名称 --></div>
</header>
</div>
</div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/goods_detail.js"></script>
</html>
2.goods_detailCon.html
移除头部的
<header class="aui-bar aui-bar-nav fix-status-bar" id="aui-header">
<a class="aui-btn aui-pull-left" tapmode onclick="api.closeWin();">
<span class="aui-iconfont aui-icon-left"></span>
</a>
<div class="aui-title"><!-- 商品名称 --></div>
</header>
3.goods_detail.js
apiready = function(){
var header = $api.byId('main'); // 获取头部
$api.fixStatusBar(header); // 处理ios
var pos = $api.offset(header); // 获取头部位置
var title = $api.dom(header,'.aui-title'); // 获取标题位置
$api.html(title,api.pageParam.title); // 设置标题内容
api.openFrame({ // 打开内容页,并传递参数
name: 'goods_detailCon',
url: 'goods_detailCon.html',
rect:{
x: 0,
y: pos.h,
w: 'auto',
h: 'auto'
},
bounces: true,
opaque: true,
vScrollBarEnabled: false,
pageParam:{
goods_id:api.pageParam.goods_id
}
});
};
4.goods_detailCon.js
apiready = function(){
fix_status_bar();// 修复头部
var goods_id = api.pageParam.goods_id;
// 获取商品相关信息
api.ajax({
url: 'http://zhudianbao.yunlutong.com/?g=Api&m=Goods&a=getGoodsInfo',
method: 'get',
data: {
values: {
goods_id: goods_id
}
}
}, function(json, err) {
if (json.status == '1') {
var interText = doT.template($("#goodstmpl").text());
$("#info_area").html(interText(json.info));
var swiper = new Swiper('.swiper-container', {
pagination: '.swiper-pagination',
paginationClickable: true,
spaceBetween: 30,
centeredSlides: true,
autoplay: 3500,
autoplayDisableOnInteraction: false
});
} else {
var toast = new auiToast();
toast.fail({
title:json.msg,
duration:2000
});
}
});
}
获取参数,根据参数获取数据,并使用doT进行页面布局。
看效果


apiCloud中实现头部与内容分离与操作规范,App头部header固定,头部与内容分离的更多相关文章
- 移动端固定头部和固定左边第一列的实现方案(Vue中实现demo)
最近移动端做一份报表,需要左右滚动时,固定左边部分:上下滚动时,固定头部部分. 代码在Vue中简单实现 主要思路是: a.左边部分滚动,实时修改右边部分的滚动条高度 b.头部和内容部分都设置固定高度, ...
- apiCloud中aui获取不到高度,pos.h为0,offsetHeight为0问题
apiCloud中aui获取不到高度,pos.h为0,offsetHeight为0问题 原HTML <div class="row aui-text-center"> ...
- apiCloud中openFrameGroup传参
apiCloud中openFrameGroup传参 1.无效的 api.openFrameGroup({ // 打开 frame 组 name: 'group', scrollEnabled: fal ...
- 在指定的div中搜索内容,并滚动显示到当前搜索到的内容处
我想要的是页面中有个带滚动条的div对象,里面有很多内容,想要用js搜索到div中的某个字符串内容,然后将div的滚动条滚动到搜索到的内容处显示,自动定位.先是查找页面中的内容,然后将找到的内容创建t ...
- apiCloud中api.ajax方法跨域传参获取数据
apiCloud中的ajax方法,可以自动处理跨域访问数据,不必使用jsonp来处理了. 使用ajax方法,必须要在apiready = function() {}方法中 获取参数 var pageP ...
- 嵌入式表单字段中的内容可能被server更改以删除不安全的内容。是否要又一次载入您的页面以查看保存结果?
嵌入式表单字段中的内容可能被server更改以删除不安全的内容.是否要又一次载入您的页面以查看保存结果? 近期有朋友问到,当他在SharePoint首页上进行编辑时.插入一段代码. 完 ...
- 输出内容 document.write() 可用于直接向 HTML 输出流写内容。简单的说就是直接在网页中输出内容
输出内容(document.write) document.write() 可用于直接向 HTML 输出流写内容.简单的说就是直接在网页中输出内容. 第一种:输出内容用""括起,直 ...
- Midnight.js – 实现奇妙的固定头部切换效果
Midnight.js 是一款 jQuery 插件,在页面滚动的时候实现多个头设计之间的切换,所以你总是有一个头与它下面的内容层叠,看起来效果很不错. Midnight.js 可以让你轻松实现这种切换 ...
- 【转载】app测试的过程和重点关注内容
针对 app测试的过程和重点关注内容,做以下梳理和总结: 1 . 首先是测试资源确认及准备 ( 1 ) 产品需求文档.产品原型图.接口说明文档以及设计说明文档等应齐全: ( 2 ) 测试设备及工具 ...
随机推荐
- 王立平--Object-c
object-c通常写作objective-c或者obj-c,是依据C语言所衍生出来的语言.继承了C语言的特性,是扩充C的面向对象编程语言. 它主要使用于MacOSX和GNUstep这两个使用Open ...
- bzj1106: [POI2007]立方体大作战tet
比较玄幻的题目. 考虑两个不同的元素 假设位置是 a...a...b...b... 那么不需要通过交换ab来消除ab,各自弄就行 若是 a...b...b...a... 那也没必要交换,先把b消掉就好 ...
- Java类的根Object
一.Object类介绍 Object全名java.lang.Object,java.lang包在使用的时候无需显示导入,编译时由编译器自动导入.Object类是类层次结构的根,Java中所有的类从根本 ...
- Request.QueryString["id"] 、Request.Params["id"] 的强大
<form> <input type="text" name="id" value="值"> </form&g ...
- git + grunt 环境配置
1⃣️ssh key生成步骤 一.设置Git的user.name和user.email: $ git config --global user.name "xiongzuyan&qu ...
- TF基础3
批标准化 批标准化(batch normalization,BN)是为了克服神经网络层数加深导致难以训练而诞生的.深度神经网络随着深度加深,收敛会越来越慢,会导致梯度弥散问题(vanishing gr ...
- 树莓派使用samba
tips:打算利用树莓派做局域网内的文件共享服务器, 实测发现树莓派挂载一个硬盘比较合适,挂载多个硬盘则会出现供电不足而挂载失败, 即使利用外置供电接入多个硬盘实测效果也不好,树莓派在IO上无法处理多 ...
- Eclipse中删除GIT分支
删除GIT分支: 删除分支时不能直接删除本分支,所以要切换到另一分支,即非删除分支. 1.右击项目——Team——Advanced——Delete Branch...: 2. 在弹出的Delete b ...
- 池(Pool)
#1 就是一个资源的集合,用的时候按照你的需要去取,用完了给人家放回去 #2 学编程的时候,老师给我们的解释过池的意思,大概是: 如果你喝水,你可以拿杯子去水龙头接.如果很多人喝水,那就只能排队去接. ...
- nginx 过滤zip 类型的文件
http://www.cnblogs.com/bass6/p/5500660.html