ตามที่ระบุชื่อฉันจะแสดงข้อความคำแนะนำเครื่องมือบนโฮเวอร์โดยใช้ jQuery ได้อย่างไร
ตามที่ระบุชื่อฉันจะแสดงข้อความคำแนะนำเครื่องมือบนโฮเวอร์โดยใช้ jQuery ได้อย่างไร
คำตอบ:
ปลั๊กอินคำแนะนำเครื่องมืออาจมีน้ำหนักมากเกินไปสำหรับสิ่งที่คุณต้องการ เพียงตั้งค่าแอตทริบิวต์ "title" ด้วยข้อความที่คุณต้องการให้แสดงในคำแนะนำเครื่องมือของคุณ
$("#yourElement").attr('title', 'This is the hover-over text');
propแทน $("#yourElement").prop('title', 'This is the hover-over text');
สิ่งต่อไปนี้จะทำงานเหมือนเสน่ห์ (สมมติว่าคุณมี div / span / table / tr / td / etc ด้วย"id"="myId")
$("#myId").hover(function() {
$(this).css('cursor','pointer').attr('title', 'This is a hover text.');
}, function() {
$(this).css('cursor','auto');
});
ในฐานะที่เป็นอภินันทนาการ.css('cursor','pointer')จะเปลี่ยนตัวชี้เมาส์เมื่อวางเมาส์เหนือ
ตามที่แนะนำ qTip และโปรเจ็กต์อื่น ๆ ค่อนข้างเก่าฉันขอแนะนำให้ใช้qTip2เนื่องจากเป็นข้อมูลล่าสุด
ลองดูที่ToolTipster
คุณสามารถทำได้โดยใช้เพียง css โดยไม่ต้องใช้ jQiuery ใด ๆ
<a class="tooltips">
Hover Me
<span>My Tooltip Text</span>
</a>
<style>
a.tooltips {
position: relative;
display: inline;
}
a.tooltips span {
position: absolute;
width: 200px;
color: #FFFFFF;
background: #000000;
height: 30px;
line-height: 30px;
text-align: center;
visibility: hidden;
border-radius: 6px;
}
a.tooltips span:after {
content: '';
position: absolute;
top: 100%;
left: 35%;
margin-left: -8px;
width: 0;
height: 0;
border-top: 8px solid #000000;
border-right: 8px solid transparent;
border-left: 8px solid transparent;
}
a:hover.tooltips span {
visibility: visible;
opacity: 0.8;
bottom: 30px;
left: 50%;
margin-left: -76px;
z-index: 999;
}
</style>
title="My tooltipแอตทริบิวต์ที่มีองค์ประกอบของตัวเอง