在标准javascript而不是jquery中使用mousedown,mousemove和mouseup触摸事件句柄

时间:2013-11-28 07:57:35

标签: javascript html css

任何正文请告诉我如何创建一个触摸事件句柄,在javascript中有3个事件可用mousedown,mousemove和mouseup?

任何想法都表示赞赏!

1 个答案:

答案 0 :(得分:0)

我对自己的问题有所了解,我正在使用它来移动我的幻灯片:

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; }

    });