當我的滑鼠懸停在影像上方時,我希望文本出現在影像上方。我嘗試了一些東西,但 onm ouseEnter/onMouseLeave 似乎最有希望。但是我遇到了一個錯誤:當我將滑鼠懸停在我的影像上時,我的文字不在這里。這是我的代碼:
<View
style={{
flex: 1,
justifyContent: "center",
}}
>
<div
onMouseEnter={() => {
<Text>Hi here</Text>;
}}
onm ouseLeave={() => {}}
>
<Image
source={screen2}
style={{
width: "80%",
height: "80%",
marginBottom: 150,
marginTop: 120,
marginLeft: "-10%",
}}
/>
</div>
</View>
uj5u.com熱心網友回復:
你可以使用一個鉤子來設定影像顯示,當滑鼠進入你設定你的鉤子為真當滑鼠離開你設定為假
const [show, setShow] = useState(false)
return (
<View
style={{
flex: 1,
justifyContent: "center",
}}
>
{show && <text>My text headers</text>}
<div
onMouseEnter={() => setShow(true)}
onm ouseLeave={() => setShow(false)}
>
<Image
source={screen2}
style={{
width: "80%",
height: "80%",
marginBottom: 150,
marginTop: 120,
marginLeft: "-10%",
}}
/>
</div>
</View>
)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/485324.html
上一篇:單擊選單中的文本時彈出視窗