1# Hover Event
2
3A hover event is triggered when the mouse slides or a stylus moves over the component on the screen.
4
5>  **NOTE**
6>
7>  - The APIs of this module are supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version.
8>  - Currently, only an external mouse device or stylus can be used to trigger a hover event.
9
10## onHover
11
12onHover(event: (isHover: boolean, event: HoverEvent) => void): T
13
14Triggered when the mouse or stylus enters or leaves the component.
15
16**Atomic service API**: This API can be used in atomic services since API version 11.
17
18**System capability**: SystemCapability.ArkUI.ArkUI.Full
19
20**Parameters**
21
22| Name             | Type                               | Mandatory| Description                                                        |
23| ------------------- | ----------------------------------- | ---- | ------------------------------------------------------------ |
24| isHover             | boolean                             | Yes  | Whether the mouse pointer or stylus is hovering over the component. The value **true** means that the mouse pointer or stylus enters the component, and **false** means that the mouse pointer or stylus leaves the component.|
25| event<sup>11+</sup> | [HoverEvent](#hoverevent11) | Yes  | Bubbling of the blocking event.                                      |
26
27**Return value**
28
29| Type| Description|
30| -------- | -------- |
31| T | Current component.|
32
33## HoverEvent<sup>11+</sup>
34
35Inherits from [BaseEvent](ts-gesture-customize-judge.md#baseevent).
36
37**Atomic service API**: This API can be used in atomic services since API version 11.
38
39**System capability**: SystemCapability.ArkUI.ArkUI.Full
40
41| Name             | Type      | Description     |
42| --------------- | ---------- | ------- |
43| stopPropagation | () => void | Stops the event from bubbling upwards or downwards.|
44
45## Example
46
47```ts
48// xxx.ets
49@Entry
50@Component
51struct HoverEventExample {
52  @State hoverText: string = 'no hover';
53  @State color: Color = Color.Blue;
54
55  build() {
56    Column({ space: 20 }) {
57      Button(this.hoverText)
58        .width(180).height(80)
59        .backgroundColor(this.color)
60        .onHover((isHover: boolean, event: HoverEvent) => {
61          // Use the onHover event to dynamically change the text content and background color of a button when the mouse pointer or stylus is hovered on it.
62          // Use event.sourceTool to determine whether the device is a mouse device or stylus.
63          if (isHover) {
64            if (event.sourceTool == SourceTool.Pen) {
65              this.hoverText = 'pen hover';
66              this.color = Color.Pink;
67            } else if (event.sourceTool == SourceTool.MOUSE) {
68              this.hoverText = 'mouse hover';
69              this.color = Color.Red;
70            }
71          } else {
72            this.hoverText = 'no hover';
73            this.color = Color.Blue;
74          }
75        })
76    }.padding({ top: 30 }).width('100%')
77  }
78}
79```
80
81Diagrams:
82
83The figure below shows how the button looks when not hovered:
84
85 ![nohover](figures/no-hover.png)
86
87The figure below shows how the button looks like when a stylus hovers on it.
88
89 ![penhover](figures/pen-hover.png)
90