我正在使用padilicious中允许滑动检测的代码(http://padilicious.com/code/touchevents/)。它不适合我,我似乎无法弄清楚为什么。我已经在这个网站上查看了类似问题的其他答案,并按照他们的解决方案,仍然没有运气。
我将来自padilicious的javascript代码保存在我的根目录中名为“js”的文件夹中名为swipesense.js的文件中。以下是我的标题:
<script src='$root/js/swipesense.js' type='text/javascript'></script>
以下代码出现在我的身上:
<div class='main_image'
ontouchstart='touchStart(event,'main_image');'
ontouchend='touchEnd(event, $next_slideURL, $previous_slideURL);'
ontouchmove='touchMove(event);'
ontouchcancel='touchCancel(event);'>
<a href='$next_slideURL' style='display:block'>
<img src='$root/$item_path/$slideFile' alt='$slideCaption from $projectTitle\n [hidden]' style='max-width:832px; max-height:500px' title='$projectTitle: $slideCaption. \nclick for next slide ($next_slideCaption). '>
</a>
</div>
我的processingRoutine()方法如下:
function processingRoutine() {
var swipedElement = document.getElementById(triggerElementID);
if ( swipeDirection == 'left' ) {
window.location.href = "www.nba.com";
} else if ( swipeDirection == 'right' ) {
window.location.href = "www.nba.com";
}
}
注意:在我的标签中,我只有class ='main_image'而没有id ='main_image'。我假设它们是可以互换的。我可能错了(如果我是,请告诉我),但我也试过包含id选项,但它也没有用。
我真的不明白为什么这不起作用。任何帮助将不胜感激!
(更新:我知道我的滑动是被检测到的,因为滑动main_image div不会导致页面滚动,没有matilicious代码就可以了。现在我只是不确定为什么例程不起作用。任何想法?)
答案 0 :(得分:0)
我想出了这个,我想我会把它发布在这里以防其他人有类似的问题。
在标记中,您必须设置ID。您必须在touchStart函数中包含与第二个参数相同的id。要更正问题中的代码:
<div class='main_image' id='swipe'
ontouchstart='touchStart(event,'swipe');'
ontouchend='touchEnd(event, $next_slideURL, $previous_slideURL);'
ontouchmove='touchMove(event);'
ontouchcancel='touchCancel(event);'>
id名称不必与类名相对应(非常明显,但我想不管怎样都提到它)。
希望这也能解决别人的问题!