is-in-viewport
Version:
An ultra-light jQuery plugin that tells you if an element is in the viewport but with a twist.
127 lines (122 loc) • 2.83 kB
HTML
<html lang="en">
<head>
<meta charset="UTF-8">
<title>
Advanced isInViewport Example
</title>
<link rel="stylesheet" href="./common.css" />
<style>
.box {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
-ms-box-sizing: border-box;
box-sizing: border-box;
background-color: #C5C7BC;
height: 501px;
width: 100%;
margin-bottom: 2px;
text-align: center;
}
p {
padding: 0;
margin: 0;
line-height: 1.5em;
position: relative;
top: 50%;
transform: translateY(-50%);
}
.box.last {
color: #C5C7BC;
}
.tolerance {
height: 100px;
width: 100%;
background-color: rgb(212, 12, 20);
background-color: rgba(255, 0, 0, 0.4);
position: fixed;
top: 0;
left: 0;
z-index: 1;
}
.tolerance:before, .tolerance:after {
content:"";
display: table;
}
.tolerance:after {
clear: both;
}
.tolerance {
zoom: 1;
/* For IE 6/7 (trigger hasLayout) */
}
.tolerance * {
padding: 36px;
color: #fff;
}
</style>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.7/jquery.min.js">
</script>
<script src="../lib/isInViewport.js">
</script>
<script src="./advanced.js">
</script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-33892300-1']);
_gaq.push(['_setDomainName', 'muditameta.com']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script');
ga.type = 'text/javascript';
ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(ga, s);
})();
</script>
</head>
<body>
<div class="tolerance">
<a href="./index.html" class="button left">Back</a>
<a class="right">Tolerance Area (Tolerance = 100px)</a>
</div>
<div id="container">
<div class="box">
<p>
1
</p>
</div>
<div class="box">
<p>
2
</p>
</div>
<div class="box">
<p>
3
</p>
</div>
<div class="box">
<p>
4
</p>
</div>
<div class="box">
<p>
5
</p>
</div>
<div class="box">
<p>
6
</p>
</div>
<div class="box last">
<p>
This div, if not in the tolerance area, will never turn light grey.
</p>
</div>
</div>
</body>
</html>