Skip to content

Crosshair

Crosshair is a full-screen mouse-following component that draws vertical and horizontal intersecting lines on the screen and displays current coordinate values.

Disclaimer and Acknowledgments This component is primarily intended for demonstration, decoration, or specific visual effect scenarios and has no actual business functional utility.

  • Source of Inspiration: The design and concept of this component are referenced from similar components in Vue Data UI.
  • Development Note: The code logic for this component was generated with the assistance of AI.

Basic Usage

TuiCrosshair is typically placed directly at the root node of a page or within a full-screen container. By default, it displays a rounded rectangular aiming box and shows the mouse's X/Y coordinates in real-time.

vue
<template>
  <div style="height: 100vh; position: relative;">
    <TuiCrosshair />
  </div>
</template>

Visual

The component provides a rich set of attributes to adjust the appearance of the crosshair, including line thickness, opacity, and the shape of the central aiming area.

Scope Shape

Toggle the shape of the central area via the scopeShape attribute:

  • rect: Rounded rectangle (default)
  • circle: Circle

Line Styles

  • lineStroke: Controls the thickness of the crosshair lines.
  • lineOpacity: Controls the opacity of the crosshair lines.
vue
<template>
  <TuiCrosshair 
    scopeShape="circle" 
    :lineStroke="0.1" 
    :lineOpacity="0.5"
    :crosshairRadius="60"
  />
</template>

Functional Configuration

Coordinates

Control whether to display the current X/Y coordinate values of the mouse via the coordinates attribute.

Aiming Point Mode

The aimingPoint attribute controls the alignment or rendering logic of the center point:

  • center: Standard centered mode.
  • side: Side offset mode.
vue
<template>
  <TuiCrosshair :coordinates="false" />
</template>

API Reference

Props

PropertyDescriptionTypeAccepted ValuesDefault
crosshairRadiusRadius/size of the central aiming area (px)Number40
lineStrokeThickness of the crosshair lines (px)Number0.2
lineOpacityOpacity of the crosshair lines (0-1)Number1
scopeShapeShape of the central aiming boxString'rect', 'circle''rect'
aimingPointAlignment mode of the aiming pointString'center', 'side''center'
coordinatesWhether to display real-time coordinate valuesBooleantrue

Released under the MIT License.