簡體   English   中英

使用標准javascript而不是jquery中的mousedown,mousemove和mouseup的觸摸事件句柄

[英]Touch event handle with mousedown, mousemove and mouseup in standard javascript not jquery

任何人都可以告訴我如何使用javascript中可用的3個事件來創建一個觸摸事件句柄,它們是mousedown,mousemove和mouseup?

任何想法表示贊賞!

我對自己的問題有一個想法,我正在使用它來移動幻燈片,如下所示:

function Dragging() {
    var isDragging = false;
    var isStartDragging = false;
    var isEndDragging = true;
    var startPoint = 0;
    $('.Content-Page-List').mousedown(function (e) {
        e = e || event;
        if (!isStartDragging && !isDragging && isEndDragging) { isStartDragging = true; isEndDragging = false; startPoint = e.pageX;  }
        else { isStartDragging = isDragging = false; }
    });
    $('.Content-Page-List').mousemove(function () {
        if (isStartDragging && !isEndDragging) { isDragging = true;}
        else { return; }
    });
    $('.Content-Page-List').mouseup(function (e) {
        e = e || event;
        var leftVal = $(this).position().left;
        if (isDragging && !isSlideMoving) {
            var oldSlide = slide;
            /* Slide move from left to right */
            if (startPoint < e.pageX) {
                if (leftVal == 0) return;
                isSlideMoving = true;
                $('.Content-Page-List').animate({ left: (leftVal + 1200) + 'px' }, 'slow', function () {
                    slide = parseInt(slide - 1);
                    contentHeight = $('.Content-Page-List').children('ul').children('li').eq(slide).height();
                    $('#page' + slide).parent().parent().css('background', 'rgba(243, 0, 0, 0.6)');
                    $('#Content-Page-List-Wrapper').css('height', contentHeight + 'px');
                    isStartDragging = isDragging = false;
                    isEndDragging = true;
                    isSlideMoving = false;
                });
            }
            /*Slide move from right to left */
            else {
                if (leftVal == -((numOfLi * 1200) - 1200) || numOfLi == 1) return;
                isSlideMoving = true;
                $('.Content-Page-List').animate({ left: (leftVal - 1200) + 'px' }, 'slow', function () {
                    slide = parseInt(slide + 1);
                    contentHeight = $('.Content-Page-List').children('ul').children('li').eq(slide).height();
                    $('#page' + slide).parent().parent().css('background', 'rgba(243, 0, 0, 0.6)');
                    $('#Content-Page-List-Wrapper').css('height', contentHeight + 'px');
                    isStartDragging = isDragging = false;
                    isEndDragging = true;
                    isSlideMoving = false;
                });
            }
            $('#page' + oldSlide).parent().parent().css('background', '#f4f4f4');
        }
        else { isStartDragging = false; isEndDragging = true; }

    });

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM