Javascript PunchJs编辑,无垂直移动
我正在尝试编辑PUNCH.js,以便拖动只能是左右的 i、 e移除垂直运动 有人知道用Punch.js实现这一点的方法吗 或者如何限制div内的垂直移动,但使用punch 这是打孔代码 谢谢你的帮助 我一辈子都不知道该怎么做。因此,我们将非常感谢您的帮助 再次感谢 梅尔Javascript PunchJs编辑,无垂直移动,javascript,jquery,html,Javascript,Jquery,Html,我正在尝试编辑PUNCH.js,以便拖动只能是左右的 i、 e移除垂直运动 有人知道用Punch.js实现这一点的方法吗 或者如何限制div内的垂直移动,但使用punch 这是打孔代码 谢谢你的帮助 我一辈子都不知道该怎么做。因此,我们将非常感谢您的帮助 再次感谢 梅尔 jQuery Touch Punch无法处理实际的移动。它所做的只是基于触摸事件模拟鼠标事件。jquery.ui.mouse.js可能是处理实际移动的工具。虽然您可以简单地删除touch.screenY、和touch.clien
jQuery Touch Punch无法处理实际的移动。它所做的只是基于触摸事件模拟鼠标事件。jquery.ui.mouse.js可能是处理实际移动的工具。虽然您可以简单地删除
touch.screenY、
和touch.clientY、
来获得您想要的。不过,这只适用于使用触摸屏的人。这不会影响使用鼠标的用户。好的,我会尝试删除它们。iv allready有一个鼠标事件设置,所以这不是问题,问题是我无法让一个触摸滑块事件工作,目前使用punch似乎是我唯一的操作…虽然我现在尝试使用SLICK.js,但我明白了。slickPlay不是一个功能!如果您有新问题,请创建一个新问题。不要在老问题上继续问新问题,因为这会让人很困惑,也无助于将来有同样问题的人。无论如何,我无法帮助你了解你在评论中提供的信息。出现错误的原因有很多,如果不查看代码,就不可能知道它是什么。好的,谢谢。
/*!
* jQuery UI Touch Punch 0.2.3
*
* Copyright 2011–2014, Dave Furfero
* Dual licensed under the MIT or GPL Version 2 licenses.
*
* Depends:
* jquery.ui.widget.js
* jquery.ui.mouse.js
*/
(function ($) {
// Detect touch support
$.support.touch = 'ontouchend' in document;
// Ignore browsers without touch support
if (!$.support.touch) {
return;
}
var mouseProto = $.ui.mouse.prototype,
_mouseInit = mouseProto._mouseInit,
_mouseDestroy = mouseProto._mouseDestroy,
touchHandled;
/**
* Simulate a mouse event based on a corresponding touch event
* @param {Object} event A touch event
* @param {String} simulatedType The corresponding mouse event
*/
function simulateMouseEvent (event, simulatedType) {
// Ignore multi-touch events
if (event.originalEvent.touches.length > 1) {
return;
}
event.preventDefault();
var touch = event.originalEvent.changedTouches[0],
simulatedEvent = document.createEvent('MouseEvents');
// Initialize the simulated mouse event using the touch event's coordinates
simulatedEvent.initMouseEvent(
simulatedType, // type
true, // bubbles
true, // cancelable
window, // view
1, // detail
touch.screenX, // screenX
touch.screenY, // screenY
touch.clientX, // clientX
touch.clientY, // clientY
false, // ctrlKey
false, // altKey
false, // shiftKey
false, // metaKey
0, // button
null // relatedTarget
);
// Dispatch the simulated event to the target element
event.target.dispatchEvent(simulatedEvent);
}
/**
* Handle the jQuery UI widget's touchstart events
* @param {Object} event The widget element's touchstart event
*/
mouseProto._touchStart = function (event) {
var self = this;
// Ignore the event if another widget is already being handled
if (touchHandled || !self._mouseCapture(event.originalEvent.changedTouches[0])) {
return;
}
// Set the flag to prevent other widgets from inheriting the touch event
touchHandled = true;
// Track movement to determine if interaction was a click
self._touchMoved = false;
// Simulate the mouseover event
simulateMouseEvent(event, 'mouseover');
// Simulate the mousemove event
simulateMouseEvent(event, 'mousemove');
// Simulate the mousedown event
simulateMouseEvent(event, 'mousedown');
};
/**
* Handle the jQuery UI widget's touchmove events
* @param {Object} event The document's touchmove event
*/
mouseProto._touchMove = function (event) {
// Ignore event if not handled
if (!touchHandled) {
return;
}
// Interaction was not a click
this._touchMoved = true;
// Simulate the mousemove event
simulateMouseEvent(event, 'mousemove');
};
/**
* Handle the jQuery UI widget's touchend events
* @param {Object} event The document's touchend event
*/
mouseProto._touchEnd = function (event) {
// Ignore event if not handled
if (!touchHandled) {
return;
}
// Simulate the mouseup event
simulateMouseEvent(event, 'mouseup');
// Simulate the mouseout event
simulateMouseEvent(event, 'mouseout');
// If the touch interaction did not move, it should trigger a click
if (!this._touchMoved) {
// Simulate the click event
simulateMouseEvent(event, 'click');
}
// Unset the flag to allow other widgets to inherit the touch event
touchHandled = false;
};
/**
* A duck punch of the $.ui.mouse _mouseInit method to support touch events.
* This method extends the widget with bound touch event handlers that
* translate touch events to mouse events and pass them to the widget's
* original mouse event handling methods.
*/
mouseProto._mouseInit = function () {
var self = this;
// Delegate the touch handlers to the widget's element
self.element.bind({
touchstart: $.proxy(self, '_touchStart'),
touchmove: $.proxy(self, '_touchMove'),
touchend: $.proxy(self, '_touchEnd')
});
// Call the original $.ui.mouse init method
_mouseInit.call(self);
};
/**
* Remove the touch event handlers
*/
mouseProto._mouseDestroy = function () {
var self = this;
// Delegate the touch handlers to the widget's element
self.element.unbind({
touchstart: $.proxy(self, '_touchStart'),
touchmove: $.proxy(self, '_touchMove'),
touchend: $.proxy(self, '_touchEnd')
});
// Call the original $.ui.mouse destroy method
_mouseDestroy.call(self);
};
})(jQuery);