Skip to content

Instantly share code, notes, and snippets.

View lancevo's full-sized avatar

Lance Vo lancevo

View GitHub Profile
@lancevo
lancevo / demo.html
Last active August 29, 2015 14:09
equalHeight jquery plug-in
<!DOCTYPE html>
<html>
<head>
<script src="//code.jquery.com/jquery-1.9.1.min.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
<style>
div { width:150px;border:10px solid #ccc;
display:inline-block;
@lancevo
lancevo / Opacity-Animation-for-updating-list.markdown
Last active August 29, 2015 14:15
Opacity Animation for updating list

Opacity Animation for updating list

Smooth transition when updating the list, all hidden items don't display as blank in layout. It animates at the parent level (ul/ol) rather than the individual level (li), to overcome several challenges:

  1. Use height:0 transition will hide the item smoothly, but it presents several issues: a) to show the item, you must provide exact pixel for height, and each item height is different so it's not possible with css alone. b) another way to get around this is when before showing the item, remove the previous hide class, it will reset the height to original, however it jerks the layout, because the height is restored before the transition.
  2. Use display:none in animation doesn't work, so putting in the last keyframe doesn't do anything.
  3. Use scale, transition, position:absolute to remove from the layout, it has the same issue as 1b. Also with position:absolute, when animating before opacity:0, the contents overlap each other,
@lancevo
lancevo / isNearBottom.js
Created March 5, 2015 22:28
check an element to see if it nears the bottom of the view port
function isNearBottom(element, marginPx){
marginPx = marginPx || 100;
var elementOffsetTop = $(element).offset().top,
nearBottomMargin = $(window).scrollTop() + $(window).height() - elementOffsetTop;
return Math.abs(nearBottomMargin) <= marginPx;
}
@lancevo
lancevo / ios-standalone-mode.js
Created March 11, 2015 17:53
check to see if the webpage open from iOS home screen (web app)
var standaloneMode = window.navigator.userAgent.indexOf('iPhone') != -1 && window.navigator.standalone == true;
// get weekday in Chicago CST
console.log( (new Date()).toLocaleDateString('en-US',{ timeZone: 'America/Chicago', weekday: 'long'}) );
// get time in Chicago CST
consoe.log( (new Date()).toLocaleTimeString('en-US',{ timeZone: 'America/Chicago', hour12: true}) )
@lancevo
lancevo / jplaceholder.html
Created November 16, 2011 22:15
jplaceholder demo
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
<script src="https://raw.github.com/lvo811/jplaceholder/master/jplaceholder.js"></script>
<h2>Example 1</h2>
<p>
Placeholder text is hidden when input field is focusing
</p>
<form id="form1">
<label>
<input name="user" jplaceholder="User ID" />
<h1>Alert</h1>
<p>Bootstrap JS</p>
<div class="alert fade in">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>Holy guacamole!</strong> Best check yo self, you're not looking too good.
</div>
<p></p><a ng-click="alert=true">Open Alert (AngularJS)</a></p>
<div class="alert fade" ng-class="{in:alert}">
<button type="button" class="close" ng-click="alert=false">×</button>
@lancevo
lancevo / mac rvm
Created May 4, 2013 01:51
new mac setup: rvm, ruby, rails,
# install ruby and rails
\curl -L https://get.rvm.io | bash -s stable --autolibs=3 --rails
/*
* AVIM JavaScript Vietnamese Input Method Source File dated 28-07-2008
*
* Copyright (C) 2004-2008 Hieu Tran Dang <lt2hieu2004 (at) users (dot) sf (dot) net
* Website: http://noname00.com/hieu
*
* You are allowed to use this software in any way you want providing:
* 1. You must retain this copyright notice at all time
* 2. You must not claim that you or any other third party is the author
* of this software in any way.
#AVIMControl {
background-image: url('transparent.png');
padding: 2px;
border: 1px solid #5b958e;
position: absolute;
top: 5px;
left: 5px;
width: 320px;
}