Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
185
rated 0 times [  192] [ 7]  / answers: 1 / hits: 16646  / 7 Years ago, mon, may 22, 2017, 12:00:00

I'm new to javascript/css and would like to make a version of a mouseover popup similar to the one that displays over the underlined words here: http://st.japantimes.co.jp/essay/?p=ey20141219
I can see the code that is used, but I'm not sure where/how to add in my own speech bubble image when I edit the code for my own project.



Here is an example of the code used on the referenced page:



HTML:



<a style=cursor:pointer; onclick=showChuPopup(event,'<b>’Twas</b><br />It was の省略');return false; onmouseover=showChuPopup(event,'<b>’Twas</b><br />It was の省略'); onmouseout=endChuPopup();>’Twas</a>


Javascript:



function showChuPopup(e,text){
if(document.all)e = event;

var obj = document.getElementById('chu_popup');
var obj2 = document.getElementById('chu_popup_text');
obj2.innerHTML = text;
obj.style.display = 'block';
var st = Math.max(document.body.scrollTop,document.documentElement.scrollTop);/*
if(navigator.userAgent.toLowerCase().indexOf('safari')>=0)st=0;*/
var leftPos = e.clientX - 100;
if(leftPos<0)leftPos = 0;
obj.style.left = leftPos + 'px';
obj.style.top = e.clientY - obj.offsetHeight -1 + st + 'px';} function endChuPopup() {
document.getElementById('chu_popup').style.display = 'none';} function touchHandler(e){
document.getElementById('chu_popup').style.display = 'none';}


Thanks for any help or ideas.


More From » html

 Answers
32

There are a few ways to go about this, but I'll recommend two options and provide links to both!






First, check out the answer on this question to see if this is what you want:



jQuery Popup Bubble/Tooltip






Second, have you thought about just using a tooltip with CSS? They're not hard to implement at all, and you can absolutely bind data to them.



(Shamelessly stolen from: https://www.w3schools.com/css/css_tooltip.asp, I would recommend poking around here and also looking into Bootstrap if you're a beginner!)



<style>
.tooltip {
position: relative;
display: inline-block;
border-bottom: 1px dotted black;
}

.tooltip .tooltiptext {
visibility: hidden;
width: 120px;
background-color: black;
color: #fff;
text-align: center;
border-radius: 6px;
padding: 5px 0;
position: absolute;
z-index: 1;
top: 150%;
left: 50%;
margin-left: -60px;
}

.tooltip .tooltiptext::after {
content: ;
position: absolute;
bottom: 100%;
left: 50%;
margin-left: -5px;
border-width: 5px;
border-style: solid;
border-color: transparent transparent black transparent;
}

.tooltip:hover .tooltiptext {
visibility: visible;
}
</style>

<div class=tooltip>Hover over me
<span class=tooltiptext>Tooltip text</span>
</div>

[#57699] Friday, May 19, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
sonja

Total Points: 541
Total Questions: 113
Total Answers: 114

Location: Anguilla
Member since Sun, Jan 29, 2023
1 Year ago
sonja questions
Mon, Nov 30, 20, 00:00, 4 Years ago
Sun, Oct 11, 20, 00:00, 4 Years ago
Thu, May 21, 20, 00:00, 4 Years ago
Sun, Nov 10, 19, 00:00, 5 Years ago
Mon, Aug 26, 19, 00:00, 5 Years ago
;