为了处理滑动,我使用此处发布的脚本: http://padilicious.com/code/touchevents/
效果很好。
现在,我希望它能够获取 <a>
中包含的链接,而不是更改背景(原始脚本的作用)。它有一个类,通常是到下一页的链接,但对于像这样的鼠标事件:
<a href="mypage02.html" target="_self" class="NextP" title="My Second Page">
然后加载页面。
我有很多页面,具有相同的结构,我不想手动定义链接。我想让js掌握当前的href
包含在<a>
中并在滑动触发时启动它。如果可能的话。
谢谢;-)
最佳答案
据我了解,您想寻找一个
<a href="http://example.com/" class="NextP">
页面中的元素(带有 <a>
类的 NextP
anchor 标记),当用户滑动时,访问该链接。
为了做到这一点,我会
- 查看 HTML 中的
a.NextP
元素,并捕获其href
属性。 - 当用户滑动时,设置
window.location.href
到这个属性。
window.onload = function(){
var nextPageUrl = document.querySelector('a.NextP').href;
// just guessing how swiping works, I haven't looked through your library
document.body.onswiperight = function(){
window.location.href = nextPageUrl;
};
};
当然,您会使用正确的方法来检测滑动。
关于javascript - 如何在 JavaScript 中通过滑动来跟踪链接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29288237/