- /*
- * 封装调用父页面方法 不需要调用方法则直接加载父页面
- *@parme fun {
- Str
- } 父页面需要调用的方法 例: reset_fun("vm.loadQuestion1()") 即可调用父页面的方法
- */
- function reset_fun(fun) {
- var father = plus.webview.currentWebview().opener();
- fun ? father.evalJS(fun) : location.reload();
- }
- /* 清空下拉加载的 box 盒子 */
- function del_down_sroll_box() {
- document.getElementById('down_load').style.opacity = 0;
- }
- /*
- * 打电话
- * */
- functioncall_phone(phoneNum){
- // 这个函数安卓有一次提示, 苹果没有提示
- varbtnArray=['拨打','取消'];
- mui.confirm('是否拨打'+phoneNum+'?','提示',btnArray,function(e){
- if(e.index==0){
- plus.device.dial(phoneNum,false);
- }
- });
- }
- /*
- * 功能: 监听上拉刷新
- * callback {
- Fun
- } 回调函数 需要进行的操作
- * el {
- Str
- } 需要监听滑动的盒子 默认 id 为 body
- */
- var PUBLIC_BODY = document.getElementsByTagName("body")[0];
- PUBLIC_DOWN_SHOW_TXT = document.createElement('div'); // 显示暂无数据
- function up_reset(callback, el) {
- if (!el) {
- // el = document.getElementById("app");
- el = PUBLIC_BODY
- }
- if (!callback) {
- callback = function() {
- }
- }
- el.addEventListener('touchstart', refreshTouchStart);
- el.addEventListener('touchmove', refreshTouchMove);
- el.addEventListener('touchend', refreshTouchend);
- var end_y, // 移动开始后坐标
- start_Y, // 移动开始前坐标
- buttonText, // 显示松开后的信息
- isReloadText = '↑ 松开刷新', // 移动时未结束移动要显示的信息
- up_down_txt_box; // 获取要显示信息的节点
- /* 开始滑动 */
- function refreshTouchStart(e) {
- var touch = e.changedTouches[0];
- end_y = 0;
- start_Y = touch.pageY; // 获得当前按下点的纵坐标
- }
- /* 滑动中 */
- function refreshTouchMove(e) {
- // 监听下滑的坐标, 达到一定程度显示, 正在刷新
- var touch = e.touches[0];
- end_y = touch.pageY - start_Y;
- up_down_txt_box = document.getElementById("up_down_txt_box")
- /* 滑动到一定范围 显示数据 */
- if (end_y> 100) {
- up_down_txt_box.style.display = 'block'
- up_down_txt_box.className = 'up_down_txt_box h_20';
- up_down_txt_box.innerhtml = isReloadText;
- }
- }
- /* 滑动结束 */
- function refreshTouchend(e) {
- // 获取显示信息的盒子
- up_down_txt_box = document.getElementById("up_down_txt_box");
- // 下拉拉刷新状态
- if (end_y> 150) {
- // 将文字更新
- up_down_txt_box.style.display = 'block'
- isReloadText = '<img src="../../images/icon/loading.gif"height="10"/> 正在更新';
- up_down_txt_box.innerHTML = isReloadText;
- // 如果回调返回 true 了 表示操作完了
- if (callback()) {
- setTimeout(function() {
- isReloadText = '<img src="../../images/lky/icon/audio_50.png"height="10"/> 更新完成';
- up_down_txt_box.innerHTML = isReloadText;
- setTimeout(function() {
- isReloadText = '↑ 松开刷新';
- up_down_txt_box.innerHTML = '';
- up_down_txt_box.classList = 'up_down_txt_box'
- up_down_txt_box.style.display = 'none'
- }, 1000)
- }, 500)
- }
- return false
- }
- }
- }
来源: http://www.jianshu.com/p/1760aafeafbf