JavaScript preprocessors can help make authoring JavaScript easier and more convenient. For instance, CoffeeScript can help prevent easy-to-make mistakes and offer a cleaner syntax and Babel can bring ECMAScript 6 features to browsers that only support ECMAScript 5.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
HTML Settings
Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.
<ul id="navigation">
<li>
<a href="#">Patas</a>
<div>
<h3>Patas</h3>
<div><img src="http://placekitten.com/320/240"></div>
</div>
</li>
<li>
<a href="#">Golden Snub-Nosed</a>
<div>
<h3>Golden Snub-Nosed</h3>
<div><img src="http://placekitten.com/g/320/240"></div>
</div>
</li>
<li>
<a href="#">Duoc Langur</a>
<div>
<h3>Duoc Langur</h3>
<div><img src="http://placekitten.com/320/240"></div>
</div>
</li>
<li>
<a href="#">Baby Pygmy Marmoset</a>
<div>
<h3>Baby Pygmy Marmoset</h3>
<div><img src="http://placekitten.com/g/320/240"></div>
</div>
</li>
<li>
<a href="#">Black Lion Tamarin</a>
<div>
<h3>Black Lion Tamarin</h3>
<div><img src="http://placekitten.com/320/240"></div>
</div>
</li>
<li>
<a href="#">Monk Saki</a>
<div>
<h3>Monk Saki</h3>
<div><img src="http://placekitten.com/g/320/240"></div>
</div>
</li>
<li>
<a href="#">Gabon Talapoin</a>
<div>
<h3>Gabon</h3>
<div><img src="http://placekitten.com/320/240"></div>
</div>
</li>
<li>
<a href="#">Grivet</a>
<div>
<h3>Grivet</h3>
<div><img src="http://placekitten.com/g/320/240"></div>
</div>
</li>
<li>
<a href="#">Red Leaf</a>
<div>
<h3>Red Leaf</h3>
<div><img src="http://placekitten.com/320/240"></div>
</div>
</li>
<li>
<a href="#">King Colobus</a>
<div>
<h3>King Colobus</h3>
<div><img src="http://placekitten.com/g/320/240"></div>
</div>
</li>
</ul>
body {
margin: 0;
}
ul {
list-style: none;
margin: 0;
padding: 0;
width: 10em;
}
ul li {
position: relative;
}
ul li a {
background-color: #EEE;
display: block;
padding: 1em;
}
ul li a + div {
background: #CCC;
clip: rect(0 0 0 0);
position: absolute;
left: 100%;
top: 0;
width: 320px;
}
li.active div {
clip: auto;
}
img {
height: 240px;
width: 320px;
}
svg {
position: absolute;
top: 0;
left: 0;
z-index: 1;
}
(function () {
document.addEventListener('DOMContentLoaded', function () {
var
inTriangle = false,
navigation = document.getElementById('navigation'),
x1, x2, x3, y1, y2, y3, link, timeout;
navigation.addEventListener('mouseenter', onmouseenter);
navigation.addEventListener('mouseleave', onmouseleave);
function isInsideTriangle() {
var
b0 = (x2 - x1) * (y3 - y1) - (x3 - x1) * (y2 - y1),
b1 = ((x2 - x0) * (y3 - y0) - (x3 - x0) * (y2 - y0)) / b0,
b2 = ((x3 - x0) * (y1 - y0) - (x1 - x0) * (y3 - y0)) / b0,
b3 = ((x1 - x0) * (y2 - y0) - (x2 - x0) * (y1 - y0)) / b0;
return b1 > 0 && b2 > 0 && b3 > 0;
}
function onmouseenter(event) {
document.addEventListener('mousemove', onmousemove);
}
function onmouseleave(event) {
document.removeEventListener('mousemove', onmousemove);
}
function onmousemove(event) {
var
// get nearest anchor
linkNominee = event.target.closest('li');
// set target coords
x0 = event.clientX;
y0 = event.clientY;
if (!linkNominee) {
clearTimeout(timeout);
if (link && !link.contains(event.target)) {
link.classList.remove('active');
link = null;
}
return;
}
// conditionally set triangle’s left point
if (linkNominee === link) {
if (!isInsideTriangle()) {
x1 = x0;
y1 = y0;
}
} else if (linkNominee !== link) {
// end if still inside another link’s triangle
if (link) {
if (isInsideTriangle()) {
clearTimeout(timeout);
timeout = setTimeout(function () {
if (link) {
link.classList.remove('active');
link = null;
}
onmousemove(event);
}, 200);
return;
}
link.classList.remove('active');
}
// set link
link = linkNominee;
var
next = link.lastElementChild.getBoundingClientRect();
// set triangle’s left point
x1 = x0;
y1 = y0;
// set triangle’s top point
x2 = next.left;
y2 = next.top;
// set triangle’s bottom point
x3 = next.left;
y3 = next.bottom;
// set link state
link.classList.add('active');
}
}
});
})();
Also see: Tab Triggers