小伙伴们在开发webapp时是否都遇到过这种类似的情况,使用fastclick解决了在ios上300ms的点击延迟之后,发现点击输入框想唤启软键盘,触点不是很灵敏,必须重压或长按才能成功唤启,快速点击是不会唤启软键盘的
如何解决ios input框唤启软键盘不灵敏问题?
两种方法:
一:可以在node_module里找到fastclick.js文件修改focus方法
加上红框的那一句话,但是不建议这样做。如果以后npm install
,就会被覆盖。
二:在引用fastclick的地方,重写focus方法。如vue项目,你可以在main.js文件里面,引入fastclick模块后,重写focus方法。
如:
import FastClick from 'fastclick'
FastClick.attach(document.body)
FastClick.prototype.focus = function(targetElement) {
var length;
if (deviceIsIOS && targetElement.setSelectionRange && targetElement.type.indexOf('date') !== 0 && targetElement.type !== 'time' && targetElement.type !== 'month' && targetElement.type !== 'email') {
length = targetElement.value.length;
targetElement.focus();
targetElement.setSelectionRange(length, length);
} else {
targetElement.focus();
}
};