script.aculo.us 拖放
DragDrop 模块可用于使任何元素可拖动,然后可以将其拖放到放置区域中。
使元素可拖动:可通过创建可拖动实例然后识别要使其可拖动的元素来制作可拖动元素
句法:
new Draggable( element_id, {options} );
可拖动选项:
Options | Description |
revert | It is used to specify whether an element should return to its original position after being dragged. |
snap | It is used to make a draggable element constraint its movements. |
zindex | It used to specify the z-index in the CSS stylesheet. |
ghosting | It is used to specify whether the element should be cloned in the drop area or move to it. |
constraint | It is used to specify the draggable directions. |
handle | It is used to specify the handle to trigger the dragging. |
starteffect | It is used to define the function which is called when the specified element starts dragging. |
revertefffect | it is used to define the function which is called when the specified element reverts the drag. |
endeffect | It is used to define the function which is called when the specified element stops dragging. |
回调选项: Options Description change onStart onEnd onDragSimilar to onDrag triggered when the position of the element changes. Triggered when a drag is initiated. Triggered when a drag is finished. Trigged continuously while the element is dragged and the mouse location is changing.
例子:
HTML
HTML
输出:
创建放置区域:现在我们将创建可放置实例以将元素放置在放置区域中。
句法:
Droppables.add( element_id, {options} );
可丢弃选项: Options Description HoverClass Containment Accept Overlap GreedyIt is used to create an active hoverclass on the drop area. It used to specify the id of the draggable element so that another element cannot be dropped in it. When true, it only allows the elements having one or more CSS properties to be dropped over it. When a direction is given (horizontal/vertical) it will allow the user to drop the element only.
If it is overflowing more than 50% in the given direction.It allows overlapping draggable inside a drop area, the draggable below another element won’t be visible.
回调选项: Description onHover onDropOptions It is triggered when an element hoversover the drop area. It is triggered when an element is dropped in the drop area.
例子:
HTML
输出: