Skip to content

Instantly share code, notes, and snippets.

// determine if an element is COMPLETELY inside the current viewport.
// surely, there must be an easier way
$.expr[':']['in-viewport'] = function(element){
var $win = $(window), $el = $(element),
// element calculations
offset = $el.offset(),
outerWidth = $el.outerWidth(),
outerHeight = $el.outerHeight(),
// simple equal column heights
// sets the height of each matched div to that of the tallest element in the collection
// Usage: $("#div1, #div2, #div3").equalHeights();
$.fn.equalHeights = function(){
var heights = [], i = this.length;
while(i--){ heights[i] = this.eq(i).height(); }
return this.height(Math.max.apply(Math, heights));
}