Skip to content

Instantly share code, notes, and snippets.

@zheeeng
Created November 4, 2015 14:52
Show Gist options
  • Save zheeeng/112c22c5de1eeecf9a22 to your computer and use it in GitHub Desktop.
Save zheeeng/112c22c5de1eeecf9a22 to your computer and use it in GitHub Desktop.
JS collection from stackoverflow.com
// jQuery Bounce Effect on click no jQuery UI -- <http://stackoverflow.com/a/10363828/4494083>
// Require jQuery
function doBounce(element, times, distance, speed) {
for(var i = 0; i < times; i++) {
element.animate({marginTop: '-='+distance}, speed)
.animate({marginTop: '+='+distance}, speed);
}
}
// Is object empty? -- <http://stackoverflow.com/a/4994244/4494083>
// Speed up calls to hasOwnProperty
var hasOwnProperty = Object.prototype.hasOwnProperty;
function isEmpty(obj) {
// null and undefined are "empty"
if (obj == null) return true;
// Assume if it has a length property with a non-zero value
// that that property is correct.
if (obj.length > 0) return false;
if (obj.length === 0) return true;
// Otherwise, does it have any properties of its own?
// Note that this doesn't handle
// toString and valueOf enumeration bugs in IE < 9
for (var key in obj) {
if (hasOwnProperty.call(obj, key)) return false;
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment