在标准javascript而非jquery中使用mousedown、mousemove和mouseup触摸事件句柄
任何人请告诉我如何用javascript中的mousedown、mousemove和mouseup三个可用事件创建触摸事件句柄在标准javascript而非jquery中使用mousedown、mousemove和mouseup触摸事件句柄,javascript,html,css,Javascript,Html,Css,任何人请告诉我如何用javascript中的mousedown、mousemove和mouseup三个可用事件创建触摸事件句柄 任何想法都很感激 我对自己的问题有了一个想法,我用它来移动幻灯片,如下所示: function Dragging() { var isDragging = false; var isStartDragging = false; var isEndDragging = true; var startPoint = 0; $('.Co
任何想法都很感激 我对自己的问题有了一个想法,我用它来移动幻灯片,如下所示:
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; }
});
函数拖动(){
var IsDraging=错误;
var=false;
var isenddraging=true;
var起始点=0;
$('.Content-Page-List').mousedown(函数(e){
e=e | |事件;
如果(!IsStartDraging&&!IsDraging&&IsEndDraging){IsStartDraging=true;IsEndDraging=false;startPoint=e.pageX;}
else{IsStartDraging=IsDraging=false;}
});
$('.Content-Page-List').mousemove(函数(){
如果(IsStartDraging&!IsEndDraging){IsDraging=true;}
else{return;}
});
$('.Content-Page-List').mouseup(函数(e){
e=e | |事件;
var leftVal=$(this).position().left;
如果(IsDraging&!isSlideMoving){
var oldSlide=幻灯片;
/*滑块从左向右移动*/
如果(起始点
您可能想阅读这篇文章:抱歉,我不想使用画布。只需纯javascript+html+css。谢谢您的回复。是的,我理解,但我试图指出文章中的事件侦听器和跟踪触摸事件。