我正在尽量让JSFiddle也适用于手机,但我所有的尝试都没有效果。在桌面上,当用户悬停在箭头上时,它将变为红色。在移动设备上,当用户触摸(为了点击它)箭头时,悬停效果会被激活并永久保存,直到在站点上的任何位置发生另一次(随机)点击。如何摆脱这个噩梦?手机上的剩余悬停效果
HTML:
<nav class="nav-fillpath">
<a class="next" onClick="load('prev')">
<span class="icon-wrap"></span>
<h3><strong>Alexis</strong> Tsipras</h3>
</a>
</nav>
CSS:
.nav-fillpath a.next:hover::after,
.nav-fillpath a.next:hover .icon-wrap::after {
-webkit-transform: translateX(-50%) rotate(55deg);
transform: translateX(-50%) rotate(55deg);
background-color: red;
}
一些很好的相关问题:
- How to simulate hover effect on touch devices?
- Hover effect stays after touch in jQueryMobile
- How to trigger a click on a link using jQuery
EDIT_0:
ontouchend="this.onclick=fix
我的链接现在没有做任何事情:
选中此How to prevent sticky hover effects for buttons on touch devices,如果我用这个之后。如果我使用=fix()
,我得到一个错误:
Uncaught TypeError: Cannot read property 'removeChild' of undefined
EDIT_1:
我试了一下Shikkediel建议,在此fiddle,但是,我没有运气。在这里,新的HTML:
<a class="next" onClick="load('prev')" ontouchend="fix()">
转问这个问题 - http://stackoverflow.com/questions/17233804/how-to-prevent-sticky-hover-effects-for-buttons -on-touch-devices – Sree
有趣的方法@sri。但是,在做了正确的答案后,我得到了:'Uncaught TypeError:无法读取'undefined'属性'removeChild' – gsamaras
如果您说任何点击都会重置悬停状态,我怀疑这是由一个新的'touchstart'触发的。那么为什么不试试'function fix(){$(window).trigger('touchstart')}'。或相关的事件/其他元素... – Shikkediel