我试图在应用导航到另一个页面之前更改链接的CSS。 我之前在链接元素中添加了一个ontouchstart
事件,以大大加快应用中的导航速度。问题是事件在CSS可以改变之前触发并导航。在移动设备触摸启动时添加CSS更改
有什么方法可以在页面更改前提供用户反馈?
其他备注:
- 这是一个SPA构建的使用AngularJS和PhoneGap的构建。
- 我发现使用
button:active
只会在点击按钮后触发,因此页面会在CSS更改之前导航。 - 我相信这将需要在触摸屏设备上进行测试才能看到效果。
- 这是我在这里的第一个问题,所以请温柔:)
下面是一些示例代码:
HTML
<a class="button" ontouchstart="goTo('#!/stats', 'buttonActive', this);" onclick="goTo('#!/stats', 'buttonActive', this);">STATS</a>
CSS
.button {
display: flex;
background-color: #000000;
color: dodgerblue;
font-size: 4vmin;
cursor: pointer;
text-decoration: none;
font-size: 7vmin;
border: 0.75vmin solid dodgerblue;
border-radius: 1vmin;
height: 8vh;
width: 40vmin;
padding: 2vmin;
margin: 5vmin auto;
align-items: center;
justify-content: center;
}
.buttonActive {
background-color: dodgerblue;
color: white;
}
JS
function goTo (location, addClass, elem) {
elem.className += addClass;
window.location.href = location;
}
也许按钮:重点? – Droid