Skip to content

Instantly share code, notes, and snippets.

View leohxj's full-sized avatar
💯
Focusing

Leo Hui leohxj

💯
Focusing
View GitHub Profile
@leohxj
leohxj / switchAlike.js
Created August 29, 2013 08:07
类似switch选择的代码
// 这类代码经常看到
var code = '2';
var name;
if (code === '2') {
name = '张三';
} else if (code === '3') {
name = '李四';
} else if (code === '4') {
name = '王五';
@leohxj
leohxj / preloadTransition.html
Created September 1, 2013 13:01
文档加载完毕再执行transition
<body class="preload">
.preload * {
  -webkit-transition: none !important;
  -moz-transition: none !important;
  -ms-transition: none !important;
  -o-transition: none !important;
}
$("window").load(function() {
  $("body").removeClass("preload");
});
var interval;
$('div').mousedown(mouseState).mouseup(mouseState);
function mouseState(e) {
if (e.type == "mouseup") {
clearInterval(interval);
}
if (e.type == "mousedown") {
//code triggers on hold
@leohxj
leohxj / delayAddClass.js
Created September 6, 2013 06:14
延迟加载class
function delaySetClass(elementId, delayTime, classToAdd, classToRemove, callback) {
var element = document.getElementById(elementId);
if (element == null) {
console.log(elementId + 'does not exit!');
return;
}
var delayTimeout = setTimeout(function() {
var oldClassName = element.className,
@leohxj
leohxj / ieListenerEvent.js
Last active December 22, 2015 15:28
IE event listener
var addEvent = window.attachEvent||window.addEventListener;
var event = window.attachEvent ? 'onclick' : 'click';
addEvent(event, function(){
alert('Hello!')
});
// another
if (!someElement.addEventListener) {
_checkbox.attachEvent("onclick", setCheckedValues);
@leohxj
leohxj / center.css
Last active December 22, 2015 15:38
垂直居中方法
.Center-Container.is-Inline {
text-align: center;
width: 100%;
height: 100%;
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
font-size: 0;
@leohxj
leohxj / isRetina.js
Created September 10, 2013 07:06
判断是否是高清屏设备
var isRetina = function(){
var mediaQuery = "(-webkit-min-device-pixel-ratio: 1.5),\
(min--moz-device-pixel-ratio: 1.5),\
(-o-min-device-pixel-ratio: 3/2),\
(min-resolution: 1.5dppx)";
if (window.devicePixelRatio > 1)
return true;
if (window.matchMedia && window.matchMedia(mediaQuery).matches)
@leohxj
leohxj / playSpritsAni.js
Last active December 22, 2015 17:39
播放序列帧动画图片
/**
* 播放序列帧图片
* @param {string} elementId 元素id
* @param {number} playTime 播放时间/ms
* @param {number} totalSpriteHeight 序列帧图片高度/px
* @param {number} startFrame 播放开始帧数(0为空白帧)
* @param {number} endFrame 播放结束帧数(总帧数+1为空白帧)
* @return {null} 没有返回值
*/
function playSpriteAni(elementId, playTime, totalSpriteHeight, startFrame, endFrame) {
@leohxj
leohxj / stopAnimate.js
Last active December 22, 2015 19:38
stopAnimate for Zepto.js
$.fn.stopAnimte = function() {
var endEvent = $.fx.transitionEnd;
this.css('transition', 'none').unbind(endEvent);
return this;
}
@leohxj
leohxj / getStyle.js
Created September 12, 2013 02:02
获取元素的style
var current = window.getComputedStyle || window.currentStyle;
xxx.current(prop);