<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<!------ Include the above in your HEAD tag ---------->
<div class="content">
<h1>Vincent van Gogh</h1>
<p>Vincent van Gogh, in full Vincent Willem van Gogh, (born March 30, 1853, <a href="#" data-hover-content="<div class='hover-content'>
<img src='https://s3-us-west-2.amazonaws.com/s.cdpn.io/344846/500px-P1040705_copyGemeentehuis_Zundert.jpg' />
<p>Zundert is a municipality and town in the south of the Netherlands, in the province of North Brabant.</p>
</div>">Zundert, Netherlands</a> — died July 29, 1890, Auvers-sur-Oise, near <a href="#" data-hover-content="<div class='hover-content'>
<img src='https://s3-us-west-2.amazonaws.com/s.cdpn.io/344846/eyfel-kulesi-paris.jpg' />
<p>Paris is the capital and most populous city of France.</p>
</div>">Paris, France</a>), Dutch painter, generally considered the greatest after <a href="#" data-hover-content="<div class='hover-content'>
<img src='https://s3-us-west-2.amazonaws.com/s.cdpn.io/344846/Rembrandt.jpg' />
<p>Rembrandt Harmenszoon van Rijn (July 15, 1606 – October 4, 1669) was a Dutch draughtsman, painter and printmaker.</p>
</div>">Rembrandt van Rijn</a>, and one of the greatest of the <a href="#" data-hover-content="<div class='hover-content'>
<img src='https://s3-us-west-2.amazonaws.com/s.cdpn.io/344846/Vincent-van-Gogh-The-Starry-Night-1889-2.jpg' />
<p>Post-Impressionism is an art movement that developed in the 1890s.</p>
</div>">Post-Impressionists.</a> The striking colour, emphatic brushwork, and contoured forms of his work powerfully influenced the current of <a href="#" data-hover-content="<div class='hover-content'>
<img src='https://s3-us-west-2.amazonaws.com/s.cdpn.io/344846/Screen%20Shot%202019-04-20%20at%2012.04.29.png' />
<p>Expressionism is a modernist movement, initially in poetry and painting, originating in Germany at the beginning of the 20th century.</p>
</div>">Expressionism</a> in modern art. Van Gogh’s art became astoundingly popular after his death, especially in the late 20th century,
when his work sold for record-breaking sums at auctions around the world and was featured in blockbuster touring exhibitions. In part because of his extensive published letters, van Gogh has also been mythologized in the popular imagination as the
quintessential tortured artist.</p>
</div>
<span class="info">Please hover a link</span>
* {
box-sizing: border-box;
}
body {
background-color: #f5f5f5;
font-family: 'Karla', sans-serif;
}
.content {
max-width: 550px;
padding: 40px;
margin: 40px auto;
}
.content > h1 {
margin: 0 0 20px 0;
font-family: 'Cookie', monospace;
font-size: 60px;
}
.content > p {
line-height: 1.7;
margin: 0;
}
.content > p > a {
color: black;
font-weight: 700;
}
.content > p > a:hover {
background-color: #ffe0b2;
}
.hover-content {
padding: 10px;
box-shadow: 0 2px 20px rgba(0,0,0,0.2);
box-sizing: border-box;
background-color: #fff;
width: 240px;
}
[data-hover-wrapper] {
transition: opacity .3s, transform .3s;
}
.hover-content > img {
max-width: 100%;
margin-bottom: 10px;
}
.hover-content > p {
font-size: 14px;
margin: 0;
line-height: 1.4;
}
.info {
position: fixed;
bottom: 0;
right: 0;
background-color: #000;
padding: 10px 20px;
color: #fff;
font-size: 13px;
}
const links = document.getElementsByTagName("a");
[...links].forEach(link => {
link.addEventListener("mouseover", handleMouseOver);
link.addEventListener("mousemove", handleMouseMove);
link.addEventListener("mouseleave", handleMouseLeave);
});
function handlePosition(e) {
const ID = e.target.getAttribute("data-hover-id");
const wrapper = document.getElementById(ID);
let top = "";
if (
!(e.target.getBoundingClientRect().top + wrapper.offsetHeight > innerHeight)
) {
top = `${e.clientY + e.target.offsetHeight}px`;
} else {
top = `${e.clientY - (wrapper.offsetHeight + e.target.offsetHeight)}px`;
}
return `position: fixed; left: ${e.clientX -
wrapper.offsetWidth / 2}px; top:${top}`;
}
function handleMouseOver(e) {
const hoverContent = e.target.getAttribute("data-hover-content");
const ID = Math.random()
.toString(36)
.substr(2, 9);
const wrapper = document.createElement("DIV");
e.target.setAttribute("data-hover-id", ID);
wrapper.setAttribute("data-hover-wrapper", "");
wrapper.setAttribute("id", ID);
wrapper.setAttribute("style", "opacity: 0; transform: scale(.8)");
wrapper.innerHTML = hoverContent;
document.body.append(wrapper);
wrapper.setAttribute("style", handlePosition(e));
// You can remove this line when you are using. I had added for the demo.
if (document.querySelector('.info')) document.querySelector('.info').remove();
}
function handleMouseLeave(e) {
const ID = e.target.getAttribute("data-hover-id");
document.getElementById(ID).style.opacity = 0;
document.getElementById(ID).style.transform = "scale(.8)";
setTimeout(() => {
document.getElementById(ID).remove();
}, 150);
}
function handleMouseMove(e) {
const ID = e.target.getAttribute("data-hover-id");
const wrapper = document.getElementById(ID);
wrapper.setAttribute("style", handlePosition(e));
}
window.addEventListener('scroll', () => {
const wrapper = document.querySelector('[data-hover-wrapper]');
if (wrapper) wrapper.remove();
});