Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将hammer.js与javascript一起使用?_Javascript_Html_Iscroll_Hammer.js_Swipeview - Fatal编程技术网

如何将hammer.js与javascript一起使用?

如何将hammer.js与javascript一起使用?,javascript,html,iscroll,hammer.js,swipeview,Javascript,Html,Iscroll,Hammer.js,Swipeview,如何使用Hammer.js我想要Phone gap中应用程序的滑动视图**确切地说-->我指的是一种循序渐进的过程。我在它的基础上找到了一些我尝试实现的方法。 它没有工作。Hammer.js中的代码 (function(Hammer) { /** * ShowTouches gesture * requires jQuery * show all touch on the screen by placing elements at there pageX a

如何使用Hammer.js我想要Phone gap中应用程序的滑动视图**确切地说-->我指的是一种循序渐进的过程。我在它的基础上找到了一些我尝试实现的方法。 它没有工作。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

而我在第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>
对此有任何补救措施或解决方案吗???

<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>
document.addEventListener( "touchstart", function(e){ onStart(e); }, false );
    function onStart ( touchEvent ) {
      if( navigator.userAgent.match(/Android/i) ) {
       touchEvent.preventDefault();
      }
    }