Skip to content

Instantly share code, notes, and snippets.

@amycheng
amycheng / inView
Created August 22, 2013 21:10
a javascript function to check if a html element is in view
function inView(el){
//check if a DOM element is in view
var scrollDistance=document.body.scrollTop;
if (scrollDistance>=el.offsetTop&&scrollDistance<el.offsetHeight+el.offsetTop) {
return true;
}else{
return false;
}
}
@amycheng
amycheng / cookie.js
Created May 10, 2013 15:37
methods for creating/reading/erasing cookies via JS
@amycheng
amycheng / transitionEnd.js
Created April 30, 2013 22:29
a simple jQuery plugin for creating callbacks for CSS3 transitions
$.fn.transitionEnd = function(callback) {
//plugin for detecting the end of a transition and then doing a callback
$(this).one('webkitTransitionEnd otransitionend msTransitionEnd transitionend',
function(e) {
if (typeof callback == 'function') {
callback.call(this);
}
});
};
@amycheng
amycheng / placeholderfallback
Created January 29, 2013 22:03
polyfill for placeholder
$(function() {
function isPlaceholderSupported() {
var input = document.createElement("input");
return ('placeholder' in input);
}
var placeholdersupport = isPlaceholderSupported();
if (placeholdersupport == false) {
// If there is no placeholder support,
@amycheng
amycheng / cleanFormJS.js
Created October 23, 2012 17:29
cleanest jQuery I've ever writtern
$formField.click(function(){
var $_this= $(this);
$_this
.css('opacity','1')
.find('input').removeAttr('disabled');
$_this.siblings()
.css('opacity','.5')
.find('input').attr('disabled','disabled');
});