The Drag Layer action lets the visitor drag a layer. Use this action to create puzzles, slider controls, and other movable interface elements.
You can specify in which direction the visitor can drag the layer (horizontally, vertically, or in any direction), a target to which the visitor should drag the layer, whether to snap the layer to the target if the layer is within a certain number of pixels of the target, what to do when the layer hits the target, and more.
Because the Drag Layer action must be called before the layer can be dragged by the visitor, make sure the event that triggers the action occurs before the visitor attempts to drag the layer. Its best to attach Drag Layer to the
body object (with the
onLoad event), though you can also attach it to a link that fills the entire layer (such as a link around an image) using the
To use the Drag Layer action:
- Select Insert > Layer or click the Draw Layer button on the Insert bar and draw a layer in the Document windows Design view.
- Select the
body tag by clicking
<body> in the tag selector at the bottom of the Document window.
- Open the Behaviors panel.
- Click the Plus (+) button and select Drag Layer from the Actions pop-up menu.
If Drag Layer is unavailable, you probably have a layer selected. Because layers do not accept events in both 4.0 browsers, you must select a different object--such as the
body tag or a link (
a tag)--or change the target browser to Internet Explorer 4.0 in the Show Events For pop-up menu.
- In the Layer pop-up menu, select the layer that you want to make draggable.
- Select either Constrained or Unconstrained from the Movement pop-up menu.
Unconstrained movement is appropriate for puzzles and other drag-and-drop games. For slider controls and moveable scenery such as file drawers, curtains, and mini-blinds, select constrained movement.
- For constrained movement, enter values (in pixels) in the Up, Down, Left, and Right text boxes.
Values are relative to the starting position of the layer. To constrain movement within a rectangular region, enter positive values in all four text boxes. To allow only vertical movement, enter positive values for Up and Down and 0 for Left and Right. To allow only horizontal movement, enter positive values for Left and Right and 0 for Up and Down.
- Enter values (in pixels) for the drop target in the Left and Top text boxes.
The drop target is the spot to which you want the visitor to drag the layer. A layer is considered to have reached the drop target when its left and top coordinates match the values you enter in the Left and Top text boxes. Values are relative to the top left corner of the browser window. Click Get Current Position to automatically fill the text boxes with the current position of the layer.
- Enter a value (in pixels) in the Snap if Within text box to determine how close the visitor must get to the drop target before the layer snaps to the target.
Larger values make it easier for the visitor to find the drop target.
- For simple puzzles and scenery manipulation, you can stop here. To define the drag handle for the layer, track the movement of the layer while it is being dragged, and trigger an action when the layer is dropped, click the Advanced tab.
- To specify that the visitor must click a particular area of the layer to drag the layer, select Area Within Layer from the Drag Handle pop-up menu; then enter the left and top coordinates and the width and height of the drag handle.
This option is useful when the image inside the layer has an element that suggests dragging, such as a title bar or drawer handle. Do not set this option if you want the visitor to be able to click anywhere in the layer to drag it.
- Select any While Dragging options that you want to use:
- Select Bring Layer to Front if the layer should move to the front of the stacking order while it is being dragged. If you select this option, use the pop-up menu to select whether to leave the layer in front or restore it to its original position in the stacking order.
- Click OK.
- Check that the default event is the one you want.
If it isnt, select another event from the pop-up menu. If the events you want are not listed, change the target browser in the Show Events For pop-up menu. Remember that layers are not supported by 3.0 browsers.
You cannot attach the Drag Layer action to an object with the