diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..98b092a
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,4 @@
+.svn
+*~
+*.kate-swp
+.*.swp
diff --git a/README b/README
new file mode 100644
index 0000000..8e498f7
--- /dev/null
+++ b/README
@@ -0,0 +1,41 @@
+Viewport adds a couple of extra selectors to jQuery. With these selectors you
+can check whether the element is inside or outside of viewport. To see how it
+works check the demo:
+http://www.appelsiini.net/projects/viewport/3x2.html
+
+The viewport selectors depend on jQuery. Include it in your header:
+
+
+
+
+Now you can use the following new selectors
+
+$(":in-viewport")
+$(":below-the-fold")
+$(":above-the-top")
+$(":left-of-screen")
+$(":right-of-screen")
+
+This is free software, licensed under the following terms:
+
+The MIT License (MIT)
+
+Copyright (c) 2008-2012 Mika Tuupola
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/jquery.viewport.js b/jquery.viewport.js
index 7826000..bfa3ce9 100644
--- a/jquery.viewport.js
+++ b/jquery.viewport.js
@@ -11,7 +11,7 @@
*
*/
(function($) {
-
+
$.belowthefold = function(element, settings) {
var fold = $(window).height() + $(window).scrollTop();
return fold <= $(element).offset().top - settings.threshold;
@@ -21,21 +21,24 @@
var top = $(window).scrollTop();
return top >= $(element).offset().top + $(element).height() - settings.threshold;
};
-
+
$.rightofscreen = function(element, settings) {
var fold = $(window).width() + $(window).scrollLeft();
return fold <= $(element).offset().left - settings.threshold;
};
-
+
$.leftofscreen = function(element, settings) {
var left = $(window).scrollLeft();
return left >= $(element).offset().left + $(element).width() - settings.threshold;
};
-
+
$.inviewport = function(element, settings) {
- return !$.rightofscreen(element, settings) && !$.leftofscreen(element, settings) && !$.belowthefold(element, settings) && !$.abovethetop(element, settings);
+ return !$.rightofscreen(element, settings)
+ && !$.leftofscreen(element, settings)
+ && !$.belowthefold(element, settings)
+ && !$.abovethetop(element, settings);
};
-
+
$.extend($.expr[':'], {
"below-the-fold": function(a, i, m) {
return $.belowthefold(a, {threshold : 0});
@@ -54,5 +57,4 @@
}
});
-
})(jQuery);