在自建的 div 或自訂元件中,為了提升用戶體驗,我們常希望鼠標滑到可點擊區域時能變成一隻「小手」,以此暗示這裡可以互動。實現方式非常簡單。
只需在目標元素上添加 cursor: pointer; 即可:
<div id="doPrint" style="border: solid; width: 64%; margin: 0 20%; height: 65%; display: block; cursor: pointer;">
手勢變化區域
</div>
除了 pointer,cursor 還有許多其他取值,能對應不同的情境語意:
auto :預設光標
default :標準箭頭
pointer, hand :手形光標
wait :等待光標
text :I 形文字光標
vertical-text :水平 I 形光標
no-drop :不可拖動光標
not-allowed :禁止(無效)光標
help :幫助光標
all-scroll :四向(三角方向)標
move :移動標
crosshair :十字精準標
透過合理運用這些取值,不僅能讓界面更直觀,也能向用戶傳達清晰的狀態提示。