JSFiddle - React, Tailwind, and code Playground
HTML
<html>
<body>
<div id="nav">
<ul>
<li><span>Link 1</span></li>
<li><span>Link 2</span></li>
<li><span>Link 3</span></li>
</ul>
</div>
<div id="container">
<div id="section"></div>
<div id="highlight"></div>
<div id="nav"></div>
</div>
</body>
</html>
CSS
body {
background: black;
color: #343333;
margin: 0;
padding: 0;
overflow: hidden;
}
a {
color: #0f0;
}
a:hover {
text-decoration: none;
}
#container {
position: relative;
width: 100%;
height: 1200px;
background-color: #343333;
background-image: url('http://www.ukbathroomstore.co.uk/images/TC-SUP-TH2-CI-B1800.jpg');
background-position: top center;
overflow: hidden;
cursor: none;
border: 0;
}
#highlight {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: url('http://nickdimatteo.com/spotlight/spotlight.png') center center;
}
#nav {
width: 400px;
border: 3px solid red;
padding: 10px;
z-index: 9999;
position: absolute;
}
#nav ul {
list-style: none;
margin: 0;
padding: 0;
}
#nav ul li {
display: block;
margin-bottom: 10px;
height: 65px;
}
#nav ul li span {
background-color: #1a1a1a;
padding: 20px;
margin-bottom: 10px;
color: #fff;
font-size: 20px;
}
JavaScript
var spot;
var nav;
window.onload = function () {
$('#container').mousemove(onMouseMove);
spot = document.getElementById('highlight');
// set the nav var for #nav element
nav = $('#nav');
nav_width = nav.width();
nav_height = nav.height();
nav_pos = nav.offset();
// set offset.left and width() of #nav to set nav_x1
nav_x1 = nav_pos.left;
// add width to offset.left to get the nav_x2
nav_x2 = nav_x1 + nav_width;
// set offset.top and height() of #nav to set nav_y1
nav_y1 = nav_pos.top;
// add height to the offset.top to get the nav_y2
nav_y2 = nav_y1 + nav_height;
}
function onMouseMove(e) {
xm = 2000 - e.clientX;
ym = 2000 - e.clientY;
spot.style.backgroundPosition = '-' + xm + 'px ' + '-' + ym + 'px';
relative_xm = 2000 - xm;
relative_ym = 2000 - ym;
if((relative_xm <= nav_x2 || relative_xm <= nav_x1) && (relative_ym == nav_y2 || relative_ym == nav_y1)) {
spot.remove();
alert("Spotlight removed because it was going into the red boundary");
}
}