ts-universal-attributes-hover-effect.md 1.8 KB
Newer Older
Z
zengyawen 已提交
1 2 3
# Hover Effect


E
esterzhou 已提交
4
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
Z
zengyawen 已提交
5 6 7 8 9 10 11 12 13 14
> This component is supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version.


## Required Permissions

None


## Attributes

E
esterzhou 已提交
15
  | Name | Type | Default Value | Description | 
Z
zengyawen 已提交
16
| -------- | -------- | -------- | -------- |
E
esterzhou 已提交
17
| hoverEffect | HoverEffect | HoverEffect.Auto | Hover effect of the component in hover state. | 
Z
zengyawen 已提交
18 19 20 21

- HoverEffect enums
    | Name | Description | 
  | -------- | -------- |
E
esterzhou 已提交
22 23 24 25
  | Auto | Default hover effect. | 
  | Scale | Scale effect. | 
  | Board | Fade-in and fade-out effect. | 
  | None | No effect. | 
Z
zengyawen 已提交
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69


## Example

  
```
@Entry
@Component
struct HoverExample {
  @State isHoverVal: boolean = false

  build() {
    Column({ space: 5 }) {
      Column({ space: 5 }) {
        Text('Scale').fontSize(20).fontColor(Color.Gray).width('90%').position({ x: 0, y: 80 })
        Column()
          .width('80%').height(200).backgroundColor(Color.Gray)
          .position({ x: 40, y: 120 })
          .hoverEffect(HoverEffect.Scale)
          .onHover((isHover: boolean) => {
            console.info('Scale' + isHover)
            this.isHoverVal = isHover
          })

        Text('Board').fontSize(20).fontColor(Color.Gray).width('90%').position({ x: 0, y: 380 })
        Column()
          .width('80%').height(200).backgroundColor(Color.Gray)
          .hoverEffect(HoverEffect.Board)
          .position({ x: 40, y: 420 })
          .onHover((isHover: boolean) => {
            console.info('HoverEffect.Board')
            this.isHoverVal = isHover
          })
      }
      .hoverEffect(HoverEffect.None)
      .width('100%').height('100%').border({ width: 1 })
      .onHover((isHover: boolean) => {
        console.info('HoverEffect.None')
        this.isHoverVal = isHover
      })
    }
  }
}
```