wie man touchstart Wert in touchend-Ereignis?
Ich will touchstart.pageX-Wert, wenn touchend-Ereignis ausgelöst wird, aber ich bin nicht immer genaue Wert. Ihre mir pageX Wert von touchend-Ereignis. Was mache ich falsch?
(function($){
$.fn.extend({
//pass the options variable to the function
swipeTest: function(options) {
var touchStart;
var options = $.extend(defaults, options);
//initilaized objects
function init(thisObj){
thisObj.addEventListener('touchstart', function(e) {
var touch = e.touches[0] || e.changedTouches[0];
touchStart = touch;
console.log('Value of touchStart.pageX in touchstart method: ' + touchStart.pageX);
}, false);
thisObj.addEventListener('touchend', function(e) {
var touch = e.touches[0] || e.changedTouches[0];
console.log('Value of touchStart.pageX in touchend method: ' + touchStart.pageX);
}, false);
}
return this.each(function() {
init(this);
});
}
});
})(jQuery);
Nach streichen auf element ich bekomme in der Konsole (wischen von Links nach rechts)
Value of touchStart.pageX in touchstart method: 132
Value of touchStart.pageX in touchend method: 417
Value of touchStart.pageX in touchstart method: 32
Value of touchStart.pageX in touchend method: 481
Whey bin ich nicht immer gleicher Wert in beiden Methoden? Ich bin zeigt auf dieselbe variable, obwohl!!
Du musst angemeldet sein, um einen Kommentar abzugeben.
Sollten Sie immer die .Zielwert der touch-variable in Ihrer end-Ereignis. Das ist, wo der touch fing von. Sie brauchen noch nicht einmal den touchStart variable, wirklich. Die Note in das end-Ereignis enthält alle Informationen, die Sie benötigen.