JSFiddle - React, Tailwind, and code Playground
by BramVanroy
HTML
<div id="wrapper">
<div id="inner">
<button>Click me</button>
</div>
</div>
<aside id="secondary"><ul></ul></aside>
<span data-begin="8" data-end="9" data-frame="verb(zijn,sg3,part_intransitive(toe))" data-id="18" data-infl="sg3" data-lcat="smain" data-lemma="toe_nemen" data-pos="verb" data-postag="WW(pv,tgw,met-t)" data-pt="ww" data-pvagr="met-t" data-pvtijd="tgw" data-rel="hd" data-root="neem_toe" data-sc="part_intransitive(toe)" data-sense="neem_toe" data-stype="declarative" data-tense="present" data-word="neemt" data-wvorm="pv" style="display:none"></span>
CSS
*, *:before, *:after {
box-sizing:border-box;
}
body {
height: 10000px;
}
#wrapper {
width: 480px;
height: 480px;
line-height: 480px;
overflow: auto;
border: 3px solid #333;
}
#inner {
width: 1280px;
height: 100%;
text-align: center;
}
aside {
border: 6px solid #333;
background: white;
padding: 8px;
position: fixed;
top: 0;
left: 0;
font-size: 12px;
font-family: sans-serif;
}
aside:after {
content:"";
position: absolute;
left: 50%;
top: -12px;
margin-left: -3px;
width: 0;
height: 0;
border-left: 6px solid transparent;
border-right: 6px solid transparent;
border-bottom: 6px solid #333;
}
aside > ul {list-style-position: inside;}
JavaScript
$("button").click(function () {
var data = $("span").data(),
sec = $("#secondary"),
$this = $(this);
sec.children("ul").empty();
$("#wrapper").addClass("clicked");
for (var i in data) {
$("<li>", {
html: "<strong>" + i + "</strong>: " + data[i]
}).prependTo(sec.children("ul"));
}
// In this case the logs display the same values, in mine they don't.
console.log("tooltip: " + sec.outerWidth() / 2);
sec.css({
"left": $this.offset().left + ($this.outerWidth() / 2) - (sec.outerWidth() / 2),
"top": $this.offset().top + $this.outerHeight() + 12
});
console.log("tooltip: " + sec.outerWidth() / 2);
});