Skip to content

Instantly share code, notes, and snippets.

View jayllellis's full-sized avatar

Jason Ellis jayllellis

View GitHub Profile
@jayllellis
jayllellis / is-on-screen.js
Last active August 29, 2015 14:05
jQuery check if element is on screen
/**
* @desc checks if current element is on screen or within viewport
* @param none
* @return int - the coordinates of the window vs. the element
*/
jQuery.fn.isOnScreen = function(){
var win = $(window);
var viewport = {
@jayllellis
jayllellis / element-exists.js
Last active August 29, 2015 14:05
jQuery check if element exists
/**
* @desc checks if current element exists
* @param none
* @return int - the number of elements present, > 0 = element exists
*/
jQuery.fn.exists = function(){ return this.length > 0; }
// Usage:
if( $('#my-div').exists() ){
// do something