Skip to content

Instantly share code, notes, and snippets.

View ericwwsun's full-sized avatar

Eric Sun ericwwsun

  • IBM iX
  • New York City
View GitHub Profile
@ericwwsun
ericwwsun / gist:2998882
Created June 26, 2012 20:53
Javascript: Background Position control by js, IE8 included
var backgroundPos,
xPos,
yPos;
if( $j("html").hasClass("ie8")) { // html class... you know... it's useful
xPos = $j(this).css("background-position-x");
yPos = Number($j(this).css("background-position-y").replace(/[^0-9-]/g, ''));
} else {
backgroundPos = $j(this).css("backgroundPosition").split(" ");
xPos = backgroundPos[0],
@ericwwsun
ericwwsun / gist:2998950
Created June 26, 2012 20:57
Javascript: Delay fire window resize handler
window.onresize = function(e) {
delay(function(){
// do something.....
}, 250);
}
var delay = (function(){
var timer = 0;
return function(callback, ms){
clearTimeout (timer);
@ericwwsun
ericwwsun / gist:2998979
Created June 26, 2012 21:00
Javascript: Keyboard navigation control, Vertically
// --------- keyboard navigation control --------- //
var isinmotion = false;
$j(document).keydown(function(e){
switch (e.keyCode) {
case 38:
//console.log("up");
if (isinmotion) {
return false;
} else {
var curr = $j("li.viewing:last");
@ericwwsun
ericwwsun / gist:2998980
Created June 26, 2012 21:01
Javascript: Keyboard navigation control, Vertically
// --------- keyboard navigation control --------- //
var isinmotion = false;
$j(document).keydown(function(e){
switch (e.keyCode) {
case 38:
//console.log("up");
if (isinmotion) {
return false;
} else {
var curr = $j("li.viewing:last");
@ericwwsun
ericwwsun / gist:2999009
Created June 26, 2012 21:06
Javascript: Delay Redirection Syntax
setTimeout( "window.location = '../yourpath/yourdestination?" + params +"';" , 3000);
@ericwwsun
ericwwsun / gist:2999079
Created June 26, 2012 21:12
Javascript: On window scrolling, do something based on % of document height
// On window scrolling
$j(window).scroll(function(){
// update the ruler's color based on scroll position
var docHeight = $j(document).height();
var scrollTop = $j(window).scrollTop();
var currPos = scrollTop/docHeight*100;
//console.log( currPos + "%");
if( (currPos > 13 && currPos < 21) || currPos > 64 ) {
//do something in between 13% and 21% and grater than 64%
} else {
@ericwwsun
ericwwsun / gist:2999231
Created June 26, 2012 21:27
Javascript: jQuery ajax example
var jqxhr = $j.ajax({
type: 'post', //post or get
url: cartUrl,
//dataType: 'json', //if necessy
data: { product : pid, qty: 1, isAjax: 1 } // Important!!
}).done(function(data){
//console.log(data.status);
if ( data.status == "SUCCESS") {
// do something...
}
@ericwwsun
ericwwsun / index.html
Created July 4, 2012 15:28
Javascript: HTML5 template - yet another
<!doctype html><!-- simplified doctype works for all previous versions of HTML as well -->
<!-- Paul Irish's technique for targeting IE, modified to only target IE6, applied to the html element instead of body -->
<!--[if lt IE 7 ]><html lang="en" class="no-js ie6"><![endif]-->
<!--[if (gt IE 6)|!(IE)]><!--><html lang="en" class="no-js"><!--<![endif]-->
<head>
<!-- simplified character encoding -->
<meta charset="utf-8">
@ericwwsun
ericwwsun / gist:3124925
Created July 16, 2012 20:44
Javascript: Project Js Pattern
var $j = jQuery.noConflict();
$j(document).ready(function(){
ms.header.init();
ms.home.init();
ms.footer.init();
}); // end of document ready
/* ------------------------------------------
* Project Namespace
@ericwwsun
ericwwsun / gist:6582606
Created September 16, 2013 15:57
[Javascript] Map object for googlemaps
PL.maps = (function(){
var map,
geoData;
var init = function(mapId,options){
var div = document.getElementById(mapId);
map = new google.maps.Map(div, options);
return map;