2

I'm trying to make a phone app with phonegap, and want to make a menu I can drag in from the left. This code is working as I want it to (at this stage), but if I remove the line $("#myElement").html(changePos); from the touchmove function, it stops working. This line is just for monitoring the numbers and I don't want it anymore, but why isn't it working without it?

var touchStartPos = {x:0, y:0};
            var windowWidth = $(window).width()*3;
            var relativePos = 0;
            var menuOpen = false;
            var menuWidth = 200;
            var touchStartPos = 0;
            var menuPos = -windowWidth;

            $("#menu").css('width', windowWidth);
            $("#menu").css('left', menuPos);

            $(document).on("touchstart", function(e) {
                touchStartPos = e.originalEvent.changedTouches[0].pageX;
                menuPos = $("#menu").position().left;
            });

            $(document).on("touchmove", function(e) {
                e.preventDefault();
                var x = e.originalEvent.changedTouches[0].pageX;
                relativePos = x - touchStartPos;
                var changePos = menuPos + relativePos;
                $("#myElement").html(changePos);
                $("#menu").css('left', changePos);
            });

            $(document).on("touchend", function(e) {
                $("#menu").css('left', -windowWidth);
                $("#myElement").html($("#menu").position().left);
            });

0 Answers0