class $moveUniAppMap {
|
constructor(arg) {
|
this.activeDom = arg.activeDom; //活动dom
|
this.adaptDom = arg.adaptDom; //适应dom
|
this.windowSize = arg.uni.getSystemInfoSync(); // 设备参数含屏幕尺寸
|
let doms = arg.uni.createSelectorQuery(); //获取dom参数uni工具
|
this.getDoms = (name, fn) => { //fn是会回调函数,不用promis
|
doms.select(name).boundingClientRect((data) => {
|
if (fn) {
|
fn(data)
|
}
|
}).exec()
|
}
|
// console.log(this.windowSize)
|
|
this.start = 0;
|
this.end = 0;
|
this.domHeight = 0;
|
this.openValue = false; //方向
|
this.useHeight = arg.useHeight; //使用的低高度
|
this.critical = arg.critical; //收缩展开的程度
|
// this.getDoms(this.activeDom, (res) => { //获取dom最大高度
|
this.maxHeight = arg.maxHeight;
|
// })
|
this.fn = (res) => {
|
if (arg.fn) {
|
arg.fn(res)
|
} else {
|
console.log(res, "未设置输出函数")
|
}
|
}
|
|
return this;
|
}
|
ListenerTouchstart(dom) { //开始移动,记录开始点和活动dom高度
|
this.start = dom.changedTouches[0].clientY;
|
this.getDoms(this.activeDom, (res) => { //动态获取当前活动dom高度
|
this.domHeight = res.height;
|
})
|
// let d = {
|
// state: "start",
|
// height: this.maxHeight,
|
// };
|
// // console.log(cha, "cha")
|
// // console.log(+endOn - +this.start, "cha")
|
// this.fn(d);
|
// console.log(this.start, "this.start")
|
}
|
ListenerTouchmove(dom) {
|
let endOn = dom.changedTouches[0].clientY;
|
// console.log(that.domHeight, that.start, endOn)
|
let usecha = +this.start - +endOn;
|
let cha = this.domHeight + usecha;
|
if (cha >= this.maxHeight) {
|
cha = this.maxHeight;
|
} else if (cha <= this.useHeight) {
|
cha = this.useHeight;
|
}
|
let translate = false;
|
if (usecha >= this.critical) {
|
translate = true;
|
}
|
if (usecha <= -this.critical) {
|
translate = true;
|
}
|
let d = {
|
state: "on",
|
height: cha,
|
translate: translate
|
};
|
if (usecha >= 0) {
|
d.state = "up";
|
}
|
// console.log(cha, "cha")
|
// console.log(usecha, "cha")
|
this.fn(d);
|
}
|
ListenerTouchend(dom) {
|
this.end = dom.changedTouches[0].clientY;
|
let cha, states;
|
if (this.end >= this.start) {
|
states = false; //方向向下收缩
|
cha = this.end - this.start;
|
} else {
|
states = true; //方向向上抬起
|
cha = this.start - this.end;
|
}
|
if (cha >= this.critical) {
|
//高
|
this.judge(states, true); //程度
|
} else if (cha < this.critical) {
|
//低
|
this.judge(states, false); //程度
|
}
|
// console.log(cha)
|
}
|
innit() {
|
|
}
|
//输出事件
|
judge(val, chengdu) {
|
let translate = '';
|
if (chengdu) {
|
this.openValue = val;
|
if (val) {
|
this.height = this.maxHeight; //给到向上的最高高度
|
} else {
|
this.height = this.useHeight; //给到向下的最低高度
|
}
|
} else {
|
this.height = this.domHeight; //给到当前高度
|
}
|
if (this.height == this.maxHeight) {
|
translate = false;
|
} else {
|
translate = true;
|
}
|
let d = {
|
state: this.openValue,
|
height: this.height,
|
translate: translate
|
};
|
// console.log(d)
|
this.fn(d);
|
}
|
}
|
|
export default $moveUniAppMap;
|