diff options
author | capjamesg <jamesg@jamesg.blog> | 2022-10-11 11:56:51 +0100 |
---|---|---|
committer | capjamesg <jamesg@jamesg.blog> | 2022-10-11 11:56:51 +0100 |
commit | 49b52e108b608b336ecbbd8bea6d26ac0adceb6e (patch) | |
tree | c279bb191ac01ee8b01b2e7fdc036528ffce6a9f /hovercard.js | |
parent | 0d4c5675574a34b13f4dd2f7eb67dc570d6b6ba4 (diff) | |
download | hovercard.js-49b52e108b608b336ecbbd8bea6d26ac0adceb6e.tar.gz hovercard.js-49b52e108b608b336ecbbd8bea6d26ac0adceb6e.zip |
add readme and example image
Diffstat (limited to 'hovercard.js')
-rw-r--r-- | hovercard.js | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/hovercard.js b/hovercard.js index 3c765c1..9b8a92e 100644 --- a/hovercard.js +++ b/hovercard.js @@ -1,8 +1,7 @@ // comment out this variable to add your own hovercards -var hovercards = { - "https://www.w3.org/community/sustyweb/": {"title": "Sustainable Web Design Community Group", "A community group -dedicated to creating sustainable websites. This group will not publish specifications." } - }; +// var hovercards = { +// "https://www.w3.org/community/sustyweb/": {"title": "Sustainable Web Design Community Group", "A community group dedicated to creating sustainable websites. This group will not publish specifications." } +// }; var article = document.getElementsByTagName("article"); @@ -11,10 +10,11 @@ dedicated to creating sustainable websites. This group will not publish specific } function hover (target_link) { - if (hovercards[target_link]) { + var hovercard_data = hovercards[target_link.href.replace(/\/+$/, "")]; + if (hovercard_data) { var new_box = document.createElement("div"); new_box.classList.add("hovercard"); - new_box.innerHTML = hovercards[target_link]; + new_box.innerHTML = "<strong>" + hovercard_data["title"] + "</strong><p>" + hovercard_data["description"] + "</p>"; new_box.style.top = window.scrollY + target_link.getBoundingClientRect().top + "px"; new_box.style.left = window.scrollX + target_link.getBoundingClientRect().left + "px"; new_box.id = "tooltip"; @@ -48,3 +48,4 @@ dedicated to creating sustainable websites. This group will not publish specific unhover(this); }); } + |