首页 > 代码库 > 手机浏览器下IScroll中click事件
手机浏览器下IScroll中click事件
产品的h5页面几乎都使用了iscroll插件,如果a标签在iscroll里,在部分手机浏览器中会出现无法点击的情况,不管是绑定click事件还是使用a标签的href属性。href属性偶尔还会能点击,click事件完全不能。
如果用button或input代替a,都能响应click事件。
如果用微信内置浏览器,都能响应click事件(nubia除外)。QQ浏览器也能响应。
也就是出现此问题跟手机本地浏览器,iscroll,a标签都有关系。
iScroll uses various techniques to scroll based on device/browser capability. Normally you don‘t need to configure the engine, iScroll is smart enough to pick the best for you.
别高兴的太早
Nonetheless it is important to understand which mechanisms iScroll works on and how to configure them.
options太多,直接看重点,click和tap
To override the native scrolling iScroll has to inhibit some default browser behaviors, such as mouse clicks. If you want your application to respond to the click event you have to explicitly set this option to true
. Please note that it is suggested to use the custom tap
event instead (see below).
重点就是这儿了,iscroll阻止了浏览器默认的行为,比如click。把click设置为true就ok了。不要问我为什么阻止了默认click之后,有的手机浏览器可以,有的不可以,这个我也不知道。- -。
如果只设置click为true,会出现部分a还是无法点击,再加上taps:true;
Set this to true
to let iScroll emit a custom tap
event when the scroll area is clicked/tapped but not scrolled.
感谢万能的stackoverflow,
手机浏览器下IScroll中click事件