Skip to content

Instantly share code, notes, and snippets.

@zmmbreeze
zmmbreeze / detect.css
Last active December 17, 2015 08:39
detect media query change in javascript
/*http://css-tricks.com/media-query-change-detection-in-javascript-through-css-animations/?utm_source=feedly*/
body {
animation-duration: 0.001s;
}
@media screen and (min-width: 1000px) {
body {
animation-name: min-width-1000px;
}
}
@media screen and (min-width: 700px) {
@zmmbreeze
zmmbreeze / mutation.css
Created May 15, 2013 03:02
Mutation event fall back
/* set up the keyframes */
@keyframes nodeInserted {
from { clip: rect(1px, auto, auto, auto); }
to { clip: rect(0px, auto, auto, auto); }
}
@-moz-keyframes nodeInserted {
from { clip: rect(1px, auto, auto, auto); }
to { clip: rect(0px, auto, auto, auto); }
}
@zmmbreeze
zmmbreeze / DetectJSEnv.js
Created June 20, 2013 08:34
Detect javascript runtime environment.
function DetectJSEnv() {
if (typeof environment === 'object' && ({}).toString.call(environment) === '[object Environment]') {
// Rhino
// Details on how to detect Rhino: https://github.com/ringo/ringojs/issues/88
return 'rhino';
} else if (typeof(window) === 'undefined') {
// Node.js
return 'node';
} else {
// Browser
@zmmbreeze
zmmbreeze / getChineseUnit.js
Created July 16, 2013 09:57
获取数字的中文单元
var getChineseUnit = function(number) {
var integer = Math.floor(number);
var digit = 0;
while (integer >= 1) {
digit++;
integer = integer / 10;
}
digit--;
integer = Math.floor(number);
var chineseUnit = ['个', '十', '百', '千', '万', '十万', '百万', '千万'];
@zmmbreeze
zmmbreeze / addChineseUnit.js
Last active December 31, 2021 02:45
为数字加上单位:万或亿
/**
* 为数字加上单位:万或亿
*
* 例如:
* 1000.01 => 1000.01
* 10000 => 1万
* 99000 => 9.9万
* 566000 => 56.6万
* 5660000 => 566万
* 44440000 => 4444万
@zmmbreeze
zmmbreeze / hidpi.less
Last active December 20, 2015 01:19
hidpi.less
// from https://github.com/neoziro/less-hidpi/blob/master/hidpi.less
// Configuration
@hidpi_min_ratio: 1.5;
@hidpi_suffix: "@2x";
// Mixin
@hidpi_query: ~"(-webkit-min-device-pixel-ratio: @{hidpi_min_ratio}), (min--moz-device-pixel-ratio: @{hidpi_min_ratio}), (-o-min-device-pixel-ratio: @{hidpi_min_ratio}), (min-resolution: @{hidpi_min_ratio}dppx)";
.hidpi(@path, @w: auto, @h: auto) {
@zmmbreeze
zmmbreeze / index.html
Created July 24, 2013 09:14
A CodePen by mzhou.
<div class="fluid-wrap">
<img src="http://placehold.it/800x600" alt="" />
</div>
@zmmbreeze
zmmbreeze / toPixel.js
Created July 29, 2013 08:59
some other unit to pixel, only for IE6,IE 7
// http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291
var PIXEL = /^\d+(px)?$/i;
function getPixelValue(element, value) {
if (PIXEL.test(value)) {
return parseInt(value);
}
var style = element.style.left;
var runtimeStyle = element.runtimeStyle.left;
element.runtimeStyle.left = element.currentStyle.left;
element.style.left = value || 0;
@zmmbreeze
zmmbreeze / A-Pen-by-mzhou.markdown
Last active December 21, 2015 16:18
A Pen by mzhou.
@zmmbreeze
zmmbreeze / drawInlineBox.js
Created September 7, 2013 14:48
use `getClientRects` to draw inline box
function drawInlineBox(el) {
el = typeof el === 'string' ?
document.getElementById(el) :
el;
var lines = document.createElement('lines');
lines.style.display = 'inline';
var children = [];
for (var i = 0, l = el.childNodes.length; i < l; i++) {
children[i] = el.childNodes[i];