Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

jQuery UI API - Mouse Interaction

jQuery UI API - Mouse Interaction

Category

Interactions | Utilities

Usage

**Description:** The base interaction layer.

Dependencies:

**Note:** Like jQuery.Widget , Mouse Interaction is not intended for direct use. It is a base layer meant purely for other widgets to inherit from. This page has documentation added to jQuery.Widget , but it contains internal methods that cannot be overridden. The public API is _mouseStart()、_mouseDrag()、_mouseStop() and _mouseCapture()。

Quick navigation

Option Method Events

cancel

delay
distance
|
_mouseCapture
_mouseDelayMet
_mouseDestroy
_mouseDistanceMet
_mouseDown
_mouseDrag
_mouseInit
_mouseMove
_mouseStart
_mouseStop
_mouseUp
| onSelect | event |
Option Type Description Default value
cancel Selector Prevent interactions from starting on the specified element.
 

代码实例:

初始化带有指定 cancel 选项的 mouse:


$( ".selector" ).mouse({ cancel: ".title" });     

After initialization, get or set cancel Option:

// getter

var cancel = $( ".selector" ).mouse( "option", "cancel" );

// setter $( ".selector" ).mouse( "option", "cancel", ".title" );     

| "input, textarea, button, select, option"| onSelect | event | delay | Number | The time in milliseconds after the mouse button is pressed until the interaction starts. This option can be used to prevent unwanted interactions when clicking on an element.

Code example:

Initializes with the specified delay The mouse option:

$( ".selector" ).mouse({ delay: 300 });

    

After initialization, get or set delay Option:

// getter

var delay = $( ".selector" ).mouse( "option", "delay" );

// setter $( ".selector" ).mouse( "option", "delay", 300 );     

| 0| onSelect | event | distance | Number | The distance in pixels the mouse must move after mousedown before the interaction starts. This option can prevent unwanted interactions when clicking on an element.

Code example:

Initializes with the specified distance The mouse option:

$( ".selector" ).mouse({ distance: 10 });

    

After initialization, get or set distance Option:

// getter

var distance = $( ".selector" ).mouse( "option", "distance" );

// setter $( ".selector" ).mouse( "option", "distance", 10 );     

| 1 |

Method Return Description
_mouseCapture() Boolean Determines whether the interaction should start based on the event target of the interaction. The default implementation always returns true。
 
  • This method accepts no arguments.
  • Code example:

    Calls the _mouseCapture method:

    $( ".selector" ).mouse( "_mouseCapture" );
    
        
    | onSelect | event | _mouseDelayMet() | Boolean | Determines whether the `delay` option has been met for the current interaction.
    • This method accepts no arguments.

    Code example:

    Calls the _mouseDelayMet method:

    $( ".selector" ).mouse( "_mouseDelayMet" );
    
        
    | onSelect | event | _mouseDestroy() | jQuery (plugin only) | Destroys the interaction event handlers. This must call the `_destroy()` method of the widget being extended.
    • This method accepts no arguments.

    Code example:

    Calls the _mouseDestroy method:

    $( ".selector" ).mouse( "_mouseDestroy" );
    
        
    | onSelect | event | _mouseDistanceMet() | Boolean | Determines whether the `distance` option has been met for the current interaction.
    • This method accepts no arguments.

    Code example:

    Calls the _mouseDistanceMet method:

    $( ".selector" ).mouse( "_mouseDistanceMet" );
    
        
    | onSelect | event | _mouseDown() | jQuery (plugin only) | Handles the start of the interaction. Confirms the event is associated with the primary mouse button, ensuring `delay` and `distance` are met before the interaction starts. When the interaction is ready to start, calls the `_mouseStart` method for the extending widget to handle.
    • This method accepts no arguments.

    Code example:

    Calls the _mouseDown method:

    $( ".selector" ).mouse( "_mouseDown" );
    
        
    | onSelect | event | _mouseDrag() | jQuery (plugin only) | The extending widget should implement a `_mouseDrag()` method to handle each move of the interaction. This method receives the mouse event associated with the mouse move.
    • This method accepts no arguments.

    Code example:

    Calls the _mouseDrag method:

    $( ".selector" ).mouse( "_mouseDrag" );
    
        
    | onSelect | event | _mouseInit() | jQuery (plugin only) | Initializes the interaction event handlers. This must call the `_create()` method from the extending widget.
    • This method accepts no arguments.

    Code example:

    Calls the _mouseInit method:

    $( ".selector" ).mouse( "_mouseInit" );
    
        
    | onSelect | event | _mouseMove() | jQuery (plugin only) | Handles each move of the interaction. Calls the [_mouseDrag](#method-_mouseDrag) method for the extending widget to handle.
    • This method accepts no arguments.

    Code example:

    Calls the _mouseMove method:

    $( ".selector" ).mouse( "_mouseMove" );
    
        
    | onSelect | event | _mouseStart() | jQuery (plugin only) | The extending widget should implement a `_mouseStart()` method to handle the start of the interaction. This method receives the mouse event associated with the start of the interaction.
    • This method accepts no arguments.

    Code example:

    Calls the _mouseStart method:

    $( ".selector" ).mouse( "_mouseStart" );
    
        
    | onSelect | event | _mouseStop() | jQuery (plugin only) | The extending widget should implement a `_mouseStop()` method to handle the end of the interaction. This method receives the mouse event associated with the end of the interaction.
    • This method accepts no arguments.

    Code example:

    Calls the _mouseStop method:

    $( ".selector" ).mouse( "_mouseStop" );
    
        
    | onSelect | event | _mouseUp() | jQuery (plugin only) | Handles the end of the interaction. Calls the [_mouseStop](#method-_mouseStop) method for the extending widget to handle.
    • This method accepts no arguments.

    Code example:

    Calls the _mouseUp method:

    $( ".selector" ).mouse( "_mouseUp" );
    
    
    |