Leaflet Map Draggable—用于使DOM元素可拖动(包括触摸支持)的类

Leaflet Map Draggable—用于使DOM元素可拖动(包括触摸支持)的类

A class for making DOM elements draggable (including touch support). Used internally for map and marker dragging. Only works for elements that were positioned with L.DomUtil.setPosition.

用于使DOM元素可拖动(包括触摸支持)的类。内部用于地图和标记拖动。仅适用于使用L.DomUtil.setPosition定位的元素。

Usage example

var draggable = new L.Draggable(elementToDrag);
draggable.enable();

Constructor

ConstructorDescription
L.Draggable(<HTMLElement> el
<HTMLElement> dragHandle?
<Boolean> preventOutline?
<Draggable optionsoptions?)
Creates a Draggable object for moving el when you start dragging the dragHandle element (equals el itself by default).
开始拖动dragHandle元素时,创建一个可拖动对象以移动el(默认情况下等于el本身)。

Options

OptionTypeDefaultDescription
clickToleranceNumber3The max number of pixels a user can shift the mouse pointer during a click for it to be considered a valid click (as opposed to a mouse drag).
用户在单击过程中可以移动鼠标指针的最大像素数,以便将其视为有效的单击(与鼠标拖动相反)。

Events

EventDataDescription
downEventFired when a drag is about to start.
拖动即将开始时激发。
dragstartEventFired when a drag starts
拖动开始时激发
predragEventFired continuously during dragging before each corresponding update of the element’s position.
在每次相应更新元素位置之前,在拖动期间连续激发。
dragEventFired continuously during dragging.
拖动过程中连续激发。
dragendDragEndEventFired when the drag ends.
拖动结束时激发。

Methods

MethodReturnsDescription
enable()Enables the dragging ability
启用拖动功能
disable()Disables the dragging ability
禁用拖动功能

▶ Methods inherited from Evented

从Evented继承的方法

MethodReturnsDescription
on(<String> type, <Function>
 fn, <Object> context?)
thisAdds a listener function (fn) to a particular event type of the object. You can optionally specify the context of the listener (object the this keyword will point to). You can also pass several space-separated types (e.g. 'click dblclick').
向对象的特定事件类型添加侦听器函数(fn)。您可以选择指定侦听器的上下文(this关键字将指向的对象)。您还可以传递几个空格分隔的类型(例如“click dblclick”)。
on(<Object> eventMap)thisAdds a set of type/listener pairs, e.g. {click: onClick, mousemove: onMouseMove}
添加一组类型/侦听器对,例如{click:onClick,mousemove:onMouseMove}
off(<String> type, <Function> 
fn?, <Object> context?)
thisRemoves a previously added listener function. If no function is specified, it will remove all the listeners of that particular event from the object. Note that if you passed a custom context to on, you must pass the same context to off in order to remove the listener.
删除以前添加的侦听器函数。如果没有指定函数,它将从对象中删除该特定事件的所有侦听器。请注意,如果您将自定义上下文传递给on,则必须将相同的上下文传递给off才能删除侦听器。
off(<Object> eventMap)thisRemoves a set of type/listener pairs.
删除一组类型/侦听器对。
off()thisRemoves all listeners to all events on the object. This includes implicitly attached events.
删除对象上所有事件的所有侦听器。这包括隐式附加的事件。
fire(<String> type, <Object> 
data?, <Boolean> propagate?)
thisFires an event of the specified type. You can optionally provide a data object — the first argument of the listener function will contain its properties. The event can optionally be propagated to event parents.
激发指定类型的事件。您可以选择提供一个数据对象-侦听器函数的第一个参数将包含其属性。可以选择将事件传播到事件父级。
listens(<String> type, <Boolean> 
propagate?)
BooleanReturns true if a particular event type has any listeners attached to it. The verification can optionally be propagated, it will return true if parents have the listener attached to it.
如果特定事件类型附加了任何侦听器,则返回true。可以选择传播验证,如果父级附加了侦听器,验证将返回true。
once()thisBehaves as on(…), except the listener will only get fired once and then removed.
表现为on(…),但监听器只会被解雇一次,然后被移除。
addEventParent(<Eventedobj)thisAdds an event parent – an Evented that will receive propagated events
添加事件父级-将接收传播事件的Evented
removeEventParent(<Eventedobj)thisRemoves an event parent, so it will stop receiving propagated events
删除事件父级,因此它将停止接收传播的事件
addEventListener()thisAlias to on(…)
removeEventListener()thisAlias to off(…)
clearAllEventListeners()thisAlias to off()
addOneTimeEventListener()thisAlias to once(…)
fireEvent()thisAlias to fire(…)
hasEventListeners()BooleanAlias to listens(…)
0 0 投票数
文章评分
订阅评论
提醒
0 评论
最旧
最新 最多投票
内联反馈
查看所有评论
0
希望看到您的想法,请您发表评论x