JSFiddle - React, Tailwind, and code Playground
by Simon Price
HTML
<link rel="stylesheet" href="http://twitter.github.com/bootstrap/assets/css/bootstrap.css">
<div class="contentPane study-program-subject">
<section id="video-space">
<div class="container">
<div id="contentfulVideo" class="">
</div>
</div>
</section>
<section id="accordions">
<div class="container">
<div class="l-accordian-container">
<a class="accordian-control">
<span>
<em></em>
</span>
</a>
<div class="l-accordian">
<div>
</div>
</div>
</div>
<div class="l-accordian-container">
<a class="accordian-control">
<span>
<em></em>
</span>
</a>
<div class="l-accordian">
<div>
<p>As part of your degree, you could:</p>
<ul>
<li>visit major engineering sites</li>
<li>use industry-standard laboratory facilities, such as wind tunnels and flight simulators</li>
<li>benefit from strong industry links</li>
<li>undertake a placement year</li>
<li>work on real consultancy-style or research projects</li>
<li>graduate with an accredited degree</li>
</ul>
</div>
</div>
</div>
<div class="l-accordian-container">
<a class="accordian-control">
<span>
<em></em>
</span>
</a>
<div class="l-accordian">
<div>
<ul>
<li>Problem...
CSS
.log {
position: fixed;
right: 20px;
top: 20px;
}
JavaScript
$.fn.is_on_screen = function(){
var win = $(window);
var viewport = {
top : win.scrollTop(),
left : win.scrollLeft()
};
viewport.right = viewport.left + win.width();
viewport.bottom = viewport.top + win.height();
var bounds = this.offset();
bounds.right = bounds.left + this.outerWidth();
bounds.bottom = bounds.top + this.outerHeight();
return (!(viewport.right < bounds.left || viewport.left > bounds.right || viewport.bottom < bounds.top || viewport.top > bounds.bottom));
};
if( $('.target').length > 0 ) { // if target element exists in DOM
if( $('.target').is_on_screen() ) { // if target element is visible on screen after DOM loaded
$('.log').html('<div class="alert alert-success">target element is visible on screen</div>'); // log info
} else {
$('.log').html('<div class="alert">target element is not visible on screen</div>'); // log info
}
}
$(window).scroll(function(){ // bind window scroll event
if( $('.target').length > 0 ) { // if target element exists in DOM
if( $('.target').is_on_screen() ) { // if target element is visible on screen after DOM loaded
$('.log').html('<div class="alert alert-success">target element is visible on screen</div>'); // log info
} else {
$('.log').html('<div class="alert">target element is not visible on screen</div>'); // log info
}
}
});