首页 > Web开发 > 详细

web初学者必备-不断更新中...

时间:2021-03-28 18:01:08      阅读:27      评论:0      收藏:0      [点我收藏+]
1.判断是否是微信浏览器
export function isWechat() {
const ua = window.navigator.userAgent.toLocaleLowerCase()
return !!ua.match(/MicroMessenger/i)
}
2. 图片压缩网站,很好用的
图片压缩:https://tinyjpg.com/
3.键盘弹起事件处理
/*
键盘弹起处理
ios 键盘弹起,window.innerHeight 不变,body、html 的 clientHeight、offsetHeight 增大,页面整体上移,暂不做特殊处理
android 键盘弹起,window.innerHeight、body、html 的 clientHeight、offsetHeight 均变小,需要将 input 框滚动到可视区
*/
const originHeight = document.documentElement.clientHeight || document.body.clientHeight
window.addEventListener(‘resize‘, () => {
const resizeHeight = document.documentElement.clientHeight || document.body.clientHeight
// android 键盘弹起
if (originHeight > resizeHeight) {
// 将元素滚动到可视区域
const activeElement = document.activeElement
const tagName = activeElement.tagName
if (tagName === ‘INPUT‘ || tagName === ‘TEXTAREA‘) {
activeElement.scrollIntoViewIfNeeded()
}
}
}, false)
 

web初学者必备-不断更新中...

原文:https://www.cnblogs.com/TheYouth/p/14588914.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!