-
Notifications
You must be signed in to change notification settings - Fork 19
/
index.html
60 lines (52 loc) · 2.17 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>onScreen • detect elements currently visible on-screen with jQuery</title>
<link href="assets/style.css" rel="stylesheet">
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-117680-14']);
_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 id="fork-me"><a href="https://github.com/benpickles/onScreen">Fork me on GitHub</a></div>
<article>
<h1>onScreen</h1>
<p>onScreen is a jQuery plugin to detect whether an element is currently
visible on-screen. It adds the <code>:onScreen</code> selector which is
used to select only those elements that are currently within the bounds
of the screen: <code>$("span:onScreen")</code>. It can also be combined
with other selectors so, for example, to return only <em>visible</em>,
on-screen elements use <code>$("span:visible:onScreen")</code>.</p>
<h2>Download</h2>
<dl>
<dt>Uncompressed (0.7Kb)</dt>
<dd><a href="jquery.onscreen.js">jquery.onscreen.js</a></dd>
<dt>Minified and gzipped (0.3Kb)</dt>
<dd><a href="jquery.onscreen.min.js">jquery.onscreen.min.js</a></dd>
</dl>
<h2>Example</h2>
<pre><code>$(function() {
setInterval(function() {
$("h2") // get all <h2>s
.css("background-color", "") // reset their background colours
.filter(":onScreen") // get only <h2>s on screen
.css("background-color", "red") // give them a red background
}, 1000) // repeat every second
})</code></pre>
</article>
<footer>
<p>
© 2011-2015 <a href="http://benpickles.com/">Ben Pickles</a>,
see <a href="https://github.com/benpickles/onScreen/blob/master/LICENCE">LICENCE</a> for details.
</p>
</footer>
</body>
</html>