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 / extend.js
Last active August 29, 2015 14:19
Helper function for extending objects
/**
* Check if object is part of the DOM
* @constructor
* @param {Object} obj element to check
*/
function isDOMElement(obj) {
return obj && typeof window !== 'undefined' && (obj === window || obj.nodeType);
}
/**
@leohxj
leohxj / common-regexp.js
Created April 15, 2015 09:17
JavaScript常用正则表达式
/<%([^%>]+)?%>/g; // 匹配<%,%>之间内容
@leohxj
leohxj / interview-setTimeout.html
Created March 18, 2015 02:12
setTimeout面试题,事件相关
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>setTimeout</title>
<script type="text/javascript">
function get(id) {
return document.getElementById(id);
}
window.onload = function () {
@leohxj
leohxj / minimal-ui.html
Last active August 29, 2015 14:13
iOS 7.1的Safari为meta标签新增minimal-ui属性,在网页加载时隐藏地址栏与导航栏,http://www.36kr.com/p/210516.html
<meta name="viewport" content="minimal-ui">
<!--
Just say goodbye to minimal-ui (for now)
http://stackoverflow.com/questions/24889100/ios-8-removed-minimal-ui-viewport-property-are-there-other-soft-fullscreen
-->
@leohxj
leohxj / prevent-img-drag.css
Created November 3, 2014 08:27
阻止图片拖拽
img {
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-o-user-select: none;
user-select: none;
}
@leohxj
leohxj / OS.gitignore
Created October 29, 2014 05:38
OS generated files
# OS generated files #
######################
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db
@leohxj
leohxj / callout.css
Created July 24, 2014 03:54
禁止长按链接与图片弹出菜单
a, img {
-webkit-touch-callout: none; /* 禁止长按链接与图片弹出菜单 */
}
html, body {
-webkit-user-select: none; /* 禁止选中文本(如无文本选中需求,此为必选项) */
user-select: none;
-webkit-tap-highlight-color: rgba(0,0,0,0);
}
@leohxj
leohxj / highlight.css
Created June 17, 2014 03:31
解决ios, android下点击元素背景阴影问题
-webkit-tap-highlight-color:rgba(255,255,255,0)
@leohxj
leohxj / findMinArrayIndex.js
Created June 11, 2014 05:45
给定一个非空的JavaScript数字数组,找到最小值的索引。(如果最小值出现不止一次,那么任何此类索引是可以接受的。) 方式一,手工方式最快
// 1
function indexOfSmallest(a) {
var lowest = 0;
for (var i = 1; i < a.length; i++) {
if (a[i] < a[lowest]) lowest = i;
}
return lowest;
}
// 2
@leohxj
leohxj / isInteger.js
Created June 2, 2014 09:20
在JavaScript中判断整型的N种方法
// 你可以使用余数运算(%),将一个数字按1求余,看看余数是不是0。
function isInteger(x) {
return x % 1 === 0;
}
// 通过Math.round()
function isInteger(x) {
return Math.round(x) === x;
}