Skip to content

Instantly share code, notes, and snippets.

@bennyzhao
bennyzhao / way1.css
Last active December 21, 2015 20:29
上下居中的几种方式
/**
* From:http://coding.smashingmagazine.com/2013/08/09/absolute-horizontal-vertical-centering-css/
*/
/** basic css
* @see Set margin -> 'auto',position -> absolute.
* And t,l,b,r to a defined value.
* .center{
* margin: auto;
@bennyzhao
bennyzhao / hack.css
Created August 30, 2013 03:53
CSS Hacks
/**
*
* Selector Hacks
*
**/
/* IE6 and below */
* html #uno { color: red }
/* IE7 */
*:first-child+html #dos { color: red }
@bennyzhao
bennyzhao / encode.js
Created August 30, 2013 04:19
HTML encoding
// use jQuery
function htmlEncode(value){
//create a in-memory div, set it's inner text(which jQuery automatically encodes)
//then grab the encoded contents back out. The div never exists on the page.
return $('<div/>').text(value).html();
}
function htmlDecode(value){
return $('<div/>').html(value).text();
@bennyzhao
bennyzhao / queryStringtoJSON.js
Created August 30, 2013 05:49
Querystring into a JSON object using JavaScript
function QueryStringToJSON() {
var pairs = location.search.slice(1).split('&');
var result = {};
pairs.forEach(function(pair) {
pair = pair.split('=');
result[pair[0]] = decodeURIComponent(pair[1] || '');
});
return JSON.parse(JSON.stringify(result));
jQuery('form').submit(function() {
jQuery(window).unbind("beforeunload");
...
});
function getCookie( name ) {
var parts = document.cookie.split(name + "=");
if (parts.length == 2) return parts.pop().split(";").shift();
}
function expireCookie( cName ) {
document.cookie =
encodeURIComponent( cName ) +
"=deleted; expires=" +
new Date( 0 ).toUTCString();
//IE VERSION CONTROL
function getInternetExplorerVersion() {
// Return value assumes failure.
var rv = -1;
if (navigator.appName == 'Microsoft Internet Explorer') {
var ua = navigator.userAgent;
var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
if (re.exec(ua) != null) rv = parseFloat(RegExp.$1);
}
var cuisines = ["Chinese","Indian"];
var sel = document.getElementById('CuisineList');
for(var i = 0; i < cuisines.length; i++) {
var opt = document.createElement('option');
opt.innerHTML = cuisines[i];
opt.value = cuisines[i];
sel.appendChild(opt);
}
//demo:http://jsfiddle.net/jackwanders/kGgkE/
@bennyzhao
bennyzhao / svg.css
Created September 19, 2013 00:39
SVG Pie Loading Effect from:http://codepen.io/bennyzhao/pen/CHLvd
svg {
display: block;
margin: 50px auto;
}
#loader
{
fill: #0088cc;
}
@bennyzhao
bennyzhao / animtion.css
Created September 19, 2013 00:50
Capture CSS3 Animation Events in JavaScript from:https://gist.github.com/kewah/4493678
#anim.enable
{
-webkit-animation: flash 1s ease 3;
-moz-animation: flash 1s ease 3;
-ms-animation: flash 1s ease 3;
-o-animation: flash 1s ease 3;
animation: flash 1s ease 3;
}
/* animation */