Javascriot touchmove无法按预期工作

时间:2019-04-23 00:03:42

标签: jquery touchmove

我正在使用以下代码实现轮播滑动。但是当尝试滑动时,它总是从列表中的第一项开始,而不是最后一个可见项。

       var slider = {
            el: {
                slider: $("#carousel-list")
            },
            touchstartx: undefined,
            touchmovex: undefined, 
            movex: undefined,
            init: function() {
                this.bindUIEvents();
            },

            bindUIEvents: function() {
                this.el.slider.on("touchstart", function(event) {
                    this.touchstartx = event.originalEvent.touches[0].clientX;
                }.bind(this));

                this.el.slider.on("touchmove", function(event) {
                    this.touchmovex =  event.originalEvent.touches[0].pageX;
                    this.movex = this.touchstartx - this.touchmovex;
                    console.log(this.touchstartx, this.touchmovex)
                    // this.touchstartx = 1;
                    this.el.slider.css('transform','translate3d(-' + this.movex + 'px,0,0)');                       
                }.bind(this));
                this.el.slider.on("touchend", function(event) {}.bind(this));
            }
        }
        slider.init();

0 个答案:

没有答案