如何使用Hammer.js。 我希望手机间隙中的应用程序滑动视图。 **确切 --->我的意思是一步一步的过程。我找到了一些基于它我尝试实施。 它没有用。 Hammer.js
中的代码(function(Hammer) {
/**
* ShowTouches gesture
* requires jQuery
* show all touch on the screen by placing elements at there pageX and pageY
* @param {Boolean} [force]
*/
Hammer.plugins.showTouches = function(force) {
// the circles under your fingers
var template = '<div style="position:absolute;z-index:9999;left:0;top:0;height:14px;width:14px;border:solid 2px #777;' +
'background:rgba(255,255,255,.7);border-radius:20px;pointer-events:none;' +
'margin-top:-9px;margin-left:-9px;"></div>';
// elements by identifier
var touch_elements = {};
var touches_index = {};
/**
* remove unused touch elements
*/
function removeUnusedElements() {
// remove unused touch elements
for(var key in touch_elements) {
if(touch_elements.hasOwnProperty(key) && !touches_index[key]) {
touch_elements[key].remove();
delete touch_elements[key];
}
}
}
Hammer.detection.register({
name: 'show_touches',
priority: 0,
handler: function(ev, inst) {
touches_index = {};
// clear old elements when not using a mouse
if(ev.pointerType != Hammer.POINTER_MOUSE && !force) {
removeUnusedElements();
return;
}
// place touches by index
for(var t= 0,total_touches=ev.touches.length; t<total_touches;t++) {
var touch = ev.touches[t];
var id = touch.identifier;
touches_index[id] = touch;
// new touch element
if(!touch_elements[id]) {
touch_elements[id] = $(template).appendTo(document.body);
}
// Paul Irish says that translate is faster then left/top
touch_elements[id].css({
left: touch.pageX,
top: touch.pageY
});
}
removeUnusedElements();
}
});
};
})(window.Hammer);
当我遵守并执行代码时,我收到了错误
04-23 14:23:40.936: E/Web Console(740): TypeError: Result of expression 'Hammer' [undefined] is not an object. at file:///android_asset/www/hammer.js:8
和
04-23 14:23:40.936: E/Web Console(740): ReferenceError: Can't find variable: Hammer at file:///android_asset/www/range.html?var%20id=results.rows.item(1).id:35
而在第35行我给了..
var hammer = new Hammer(document.getElementById("pageWrapper"));
HTML
<div id="pageWrapper">
<div class="page" >
<h4 style="background-image:url(img/______.png); margin-bottom:80px; text-align:center;">hello</h4>
<img src="img/______.png" style="margin-left:5px;" /><img align="middle" />
</div>
因为,我遇到了错误,我尝试使用来自[here](https://github.com/cubiq/SwipeView/blob/master/src/swipeview.js)的SwipeView.js实现它,它进入循环...页面控制器显示但是。以下内容缺少
我也发现警告因为我们正在等待WebCore的降落响应而失误。
我尝试添加以下代码......没有变化
document.addEventListener( "touchstart", function(e){ onStart(e); }, false );
function onStart ( touchEvent ) {
if( navigator.userAgent.match(/Android/i) ) {
touchEvent.preventDefault();
}
}
针对此问题的任何补救措施或解决方案