heading anchors
v2.0.2
heading-anchorsส่วนประกอบเว็บเพื่อเพิ่มลิงก์แองเคอร์ไปยังส่วนหัวด้วย ID
การสาธิต การสาธิตสไตล์ การอ่านเพิ่มเติม
< script type =" module " src =" heading-anchors.js " > </ script >
< heading-anchors >
< h2 id =" heading-level-2 " > Heading level 2 </ h2 >
< p > Lorem ipsum dolor sit amet consectetur adipisicing elit. </ p >
< h3 id =" heading-level-3 " > Heading level 3 </ h3 >
< p >
Excepturi eligendi exercitationem, ratione, in delectus vitae veritatis
dolorem porro cupiditate quam eaque voluptates.
</ p >
</ heading-anchors > องค์ประกอบเว็บนี้ช่วยให้คุณ:
selectorposition ตำแหน่ง คุณมีตัวเลือกเล็กน้อย (เลือกหนึ่งในนั้น):
npm install @daviddarnes/heading-anchors (เช่น Avaialbe บน JSR) ตรวจสอบให้แน่ใจว่าคุณรวม <script> ในโครงการของคุณ (เลือกหนึ่งในนั้น):
<!-- Host yourself -->
< script type =" module " src =" heading-anchors.js " > </ script > <!-- 3rd party CDN, not recommended for production use -->
< script
type =" module "
src =" https://www.unpkg.com/@daviddarnes/[email protected]/heading-anchors.js "
> </ script > <!-- 3rd party CDN, not recommended for production use -->
< script
type =" module "
src =" https://esm.sh/@daviddarnes/[email protected] "
> </ script >selector และ position โดยค่าเริ่มต้น heading-anchors จะเลือกองค์ประกอบ h2[id] , h3[id] และ h4[id] ทั้งหมดภายในเพื่อผนวกลิงค์จุดยึดเข้าด้วยกัน อย่างไรก็ตามด้วยแอตทริบิวต์ selector คุณสามารถส่งผ่านสตริงตัวเลือกอื่นเพื่อเลือก:
< heading-anchors selector =" h2[id] " >
<!-- ... -->
</ heading-anchors > หมายเหตุ: ขอแนะนำให้คุณใช้ตัวเลือกที่ใช้ตัวเลือกแอตทริบิวต์ [id] เพื่อความน่าเชื่อถือที่ดีขึ้น
โดยเริ่มต้น heading-anchors จะผนวกลิงค์ยึดทันทีหลังจากองค์ประกอบโดยใช้ insertAdjacentHTML API อย่างไรก็ตามคุณสามารถปรับสิ่งนี้โดยใช้แอตทริบิวต์ position :
< heading-anchors position =" beforeend " >
<!-- ... -->
</ heading-anchors > ด้วยขอบคุณผู้คนต่อไปนี้: