如何通过在 javascript 中滑动来关注 link?
How to follow a link via swipe in javascript?
为了处理滑动,我使用了此处发布的脚本:
http://padilicious.com/code/touchevents/
它工作正常。
现在我不想更改背景(原始脚本的作用),而是希望它获取包含在 <a>
中的 link,其中包含 class,并且通常是 link 到下一页,但是对于像这样的鼠标事件:
<a href="mypage02.html" target="_self" class="NextP" title="My Second Page">
然后加载页面。
我有很多页面,结构相同,我不想手动定义link。我希望 js 掌握 <a>
中包含的当前 href
并在滑动触发时启动它。如果可以的话。
谢谢 ;-)
据我了解,您想找一个
<a href="http://example.com/" class="NextP">
页面中的 元素(带有 NextP
class 的 <a>
锚标记),当用户滑动时,访问该 link.
为此,我会
- 在您的 HTML 中查找
a.NextP
元素,并捕获其 href
属性。
- 当用户滑动时,将
window.location.href
设置为该属性。
window.onload = function(){
var nextPageUrl = document.querySelectorAll('a.NextP')[0].href;
// just guessing how swiping works, I haven't looked through your library
document.body.onswiperight = function(){
window.location.href = nextPageUrl;
};
};
当然,你会使用正确的检测滑动的方法。
为了处理滑动,我使用了此处发布的脚本: http://padilicious.com/code/touchevents/
它工作正常。
现在我不想更改背景(原始脚本的作用),而是希望它获取包含在 <a>
中的 link,其中包含 class,并且通常是 link 到下一页,但是对于像这样的鼠标事件:
<a href="mypage02.html" target="_self" class="NextP" title="My Second Page">
然后加载页面。
我有很多页面,结构相同,我不想手动定义link。我希望 js 掌握 <a>
中包含的当前 href
并在滑动触发时启动它。如果可以的话。
谢谢 ;-)
据我了解,您想找一个
<a href="http://example.com/" class="NextP">
页面中的 元素(带有 NextP
class 的 <a>
锚标记),当用户滑动时,访问该 link.
为此,我会
- 在您的 HTML 中查找
a.NextP
元素,并捕获其href
属性。 - 当用户滑动时,将
window.location.href
设置为该属性。
window.onload = function(){
var nextPageUrl = document.querySelectorAll('a.NextP')[0].href;
// just guessing how swiping works, I haven't looked through your library
document.body.onswiperight = function(){
window.location.href = nextPageUrl;
};
};
当然,你会使用正确的检测滑动的方法。