监听页面中所有input输入框,对焦点和失去焦点时做优化判断处理
let inputs = document.getElementsByTagName('input');
let timer = null;
for (let input of inputs) {
input.addEventListener('blur', function() {
timer = setTimeout(() => {
window.scrollTo(0, 0);
timer = null;
}, 0);
}, false);
input.addEventListener('focus', function() {
timer && clearTimeout(timer);
}, false);
}
安卓手机页面如果设置全屏,软键盘弹起收回后,整体页面会被压缩;
全屏设置需要针对不同浏览器做判断,否则ios或者安卓会不兼容;
全屏插件---安卓适用
export default {
install(Vue, options) {
Vue.prototype.$screenFull = function () {
let element = document.documentElement;
console.log('全屏', this.fullscreen)
if (this.fullscreen) {
if (document.exitFullscreen) {
document.exitFullscreen();
} else if (document.webkitCancelFullScreen) {
document.webkitCancelFullScreen();
} else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if (document.msExitFullscreen) {
document.msExitFullscreen();
}
} else {
if (element.requestFullscreen) {
element.requestFullscreen();
} else if (element.webkitRequestFullScreen) {
element.webkitRequestFullScreen();
} else if (element.mozRequestFullScreen) {
element.mozRequestFullScreen();
} else if (element.msRequestFullscreen) {
// IE11
element.msRequestFullscreen();
}
}
this.fullscreen = !this.fullscreen;
//this.isFullscreen = true
}
}
}
网友评论