Note: After saving, you have to bypass your browser's cache to see the changes. Internet Explorer: press Ctrl-F5, Mozilla: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Opera/Konqueror: press F5, Safari: hold down Shift + Alt while clicking Reload, Chrome: hold down Shift while clicking Reload.
// A few bugs fixed by [[User:Rillke]] (including undefined variable j, wrong calculation of offsetTop, ...)// Original description follows:// / <reference path="jquery-1.4.2.min.js"/>/*@author Daniel Gidmanreleased under GNU General Public License v3http://www.gnu.org/licenses/gpl.htmlversion 1September 2, 2010*//* * @description * adds a ":in-view"- "property" (returns (bool) whether at least one element is visible * adds a .visible()- method to each jQuery node-object that returns all elements of the set of selected elements that are actually visible (= on screen and not hidden) * useful for loading contents on demand and other stuff * @example * $('selector').visible().fadeIn(); * @example * if $('selector:in-view') loadOnDemand(); * *//*global jQuery:false*//*jshint curly:false*/(function($){'use strict';$.fn.inView=$.fn.visible=function(){// / <summary>Filter that checks if the item(s) is visible within the page. Returns set of visible elements</summary>// / <returns type="jQuery" />// sanity check aborts when no elements visiblereturnthis.filter(":visible").filter(function(){varadd=true,elem=this,$el=$(this),// 1) select only scrollable parents$ps=$el.parents().filter(function(){return(this.scrollHeight>this.offsetHeight||this.scrollWidth>this.offsetWidth);});// 2) loop through the parent elements checking that // each scrollable element is visible in parent.$ps.each(function(i,p){varelOffs=$el.offset(),$p=$(p),pOffs=$p.offset();// HTML had a negative offset and then it changed completely (to 0)if($p.filter('html').length){pOffs.top=$p.scrollTop();pOffs.left=$p.scrollLeft();}add=add&&(elOffs.top>=pOffs.top&&// is above viewport?$el.height()+elOffs.top-pOffs.top<=$p.height()&&// is below viewport?elOffs.left>=pOffs.left&&// is left from viewport?$el.width()+elOffs.left-pOffs.left<=$p.width());// is right from viewport?$el=$p;if(!add)returnfalse;});returnadd;});};$.extend($.expr.pseudos,{"in-view":function(a,i,m){return$(a).visible().length>0;}});})(jQuery);