1.vue中解决光标跑位,IOS中不适配
2. 首先还是要对弹框将fixed, 对于其父盒子relative定位
3.position:absolute,页面滚动了多少就给他,加多少top值;
if(app.isiOS) {
this.TopDom = document.querySelector('.price_container');
this.curTop = parseFloat(window.getComputedStyle(this.TopDom ).top) ;
this.focusBlur(document.querySelector('.price_modal'));
}
focusBlur(modalElem) {
if (!modalElem) {
return ;
}
let startTime, endTime;
let inputDomArr = Array.from(modalElem.querySelectorAll('input'));
let textareaDomArr = Array.from(modalElem.querySelectorAll('textarea'));
let domArr = [...inputDomArr, ...textareaDomArr];
let setTop = this.setTop;
window.scrollTo(0, 0);
modalElem.style.position = 'absolute';
domArr.forEach((elem) => {
elem.addEventListener('focus', () => {
setTop('focus')
endTime = Date.now();
});
elem.addEventListener('blur', () => {
setTop('blur')
startTime = Date.now();
let timer = setTimeout(function() {
if (Math.abs(endTime - startTime) > 30) {
window.scrollTo(0, 0);
}
clearTimeout(timer);
}, 40);
});
})
},
// 页面滚动多少,就跟top加多少值
setTop(type){
if(type=='focus'){
const scrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop;
window.console.log(scrollTop)
this.TopDom.style.top = scrollTop + this.curTop +'px';
}else if(type=='blur'){
this.TopDom.style.top = this.curTop +'px';
}
},