Skip to content

Instantly share code, notes, and snippets.

View lancevo's full-sized avatar

Lance Vo lancevo

View GitHub Profile
@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;
@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 / 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 / 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;
// social share
$(".social-share").on('click','a', function(e){
var url = $(this).attr('href');
if (!url.match(/^mailto/)) {
e.preventDefault();
window.open(url,"SocialShare","location=no,menu=no,toolbar=no");
}
});
//+ Jonas Raoni Soares Silva
//@ http://jsfromhell.com/classes/bignumber [rev. #4]
BigNumber = function(n, p, r){
var o = this, i;
if(n instanceof BigNumber){
for(i in {precision: 0, roundType: 0, _s: 0, _f: 0}) o[i] = n[i];
o._d = n._d.slice();
return;
}
@lancevo
lancevo / splitStringToArray.js
Created October 10, 2013 15:03
clean up spaces and split into array
str.trim(str).replace(/\s{2,}/g,' ').split(' ')
@lancevo
lancevo / index.html
Created August 23, 2013 14:04
A Pen by Lance Vo.
<div id="slides" class="">
<div id="slide1" class="slide">
<button class="menu-btn">Close</button>
<ol>
<li> Item </li>
<li> Item </li>
<li> Item </li>
<li> Item </li>
<li> Item </li>
<li> Item </li>
@lancevo
lancevo / offcanvas.html
Created August 20, 2013 16:29
solved transition flickering when transition to the top of 2nd page. Both panels are positioned absolute, and using translate3d to move the panel. Each panel has its own overflow setting, so it doesn't impact other panel. Padding-bottom is added to the parent panel (#panels), so it'll hide the toolbars (tested on iOS 6, may not work on iOS 7)
<!doctype html>
<html>
<head>
<meta name="viewport" content="width=device-width, user-scalable=no initial-scale=1.0">
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<style>
html, body {
height: 100%;
}
@lancevo
lancevo / index.html
Created August 20, 2013 13:11
A CodePen by Lance Vo.
<div id="slides">
<nav class="slide">
<ol>
<li> Item </li>
<li> Item </li>
<li> Item </li>
<li> Item </li>
<li> Item </li>
<li> Item </li>