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 / isTouch.js
Created September 13, 2013 08:04
原生JS判断触摸屏事件
var isTouch = 'ontouchstart' in document.documentElement;
var interaction = {
tap: isTouch ? "touchend" : "click",
down: isTouch ? "touchstart" : "mousedown",
move: isTouch ? "touchmove" : "mousemove",
stop: isTouch ? "touchend touchcancel" : "mouseup",
hover: isTouch ? "touchstart" : "mouseover"
};
@leohxj
leohxj / objSwitch.js
Created September 13, 2013 09:21
jQuery与DOM对象转换
// DOM -> jquery
var $nav = $('#nav');
// jquery -> DOM
var nav = $('#nav')[0];
@leohxj
leohxj / netstat
Created September 13, 2013 09:30
window查看端口占用情况
查看端口使用:
netstat -ano | findstr "80"
查看PID:
tasklist | findstr "1322"
@leohxj
leohxj / pertty.js
Created September 20, 2013 07:27
ASCII Art
var pertty = " .3###M#####BBMAG&AHBA&hX23GABH23HHH#MAAh&AHHHAHH5. \n"+ " G@@@@@@@#HAH#@@@@@@@@@@M#@h;SM2rM@&M#AH3925A@@@@@@: \n"+ " .5i#@@@@@@hXH@@@@@@@@@@@@@@@@@@@@sriM@3;i2GA@&299H@@@@@S \n"+ " X@@@@@@@@Hh&@@@BXX5iiS2GGH#@#h&G#@#,sAAX;:rB@@@BXss2A##@@@S \n"+ " 2A .@@@@@HM@@@Hr,;9M#@@@#MAhhHAX5h@@ss@5Bh,#@@@#i,;3M#@@@@@@@ \n"+ " ,Mi @@@BA@@@MS:;H@@@@@@@@@@@Bii3SrH@@H@H3G&@#@@&:2@@@@@@@@@@@i \n"+ " ;s,5@HA#@@522SH@@@
@leohxj
leohxj / video-buffer.js
Created September 26, 2013 07:41
设置视频的缓冲时间
var isBufferTimeInterval = false,
bufferTimeout,
newTime = 0,
oldTime = 0,
bufferRange,
isEnded,
isBufferEnded,
isPlaying = false;
var isAnimateIn = false,
@leohxj
leohxj / youtube.html
Created September 30, 2013 04:58
创建Youtube播放器
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>HTML5 MediaElement</title>
<link rel="stylesheet" href="style/normalize.css">
<link rel="stylesheet" href="style/style-youtube.css">
</head>
<body>
<div class="video-wrapper">
@leohxj
leohxj / insertJquery.js
Created October 4, 2013 06:13
插入jQuery
/* insert jQuery in Developer Tools */
var jq = document.createElement('script');
jq.src = "https://code.jquery.com/jquery-1.10.1.min.js";
document.getElementsByTagName('head')[0].appendChild(jq);
jQuery.noConflict();
/* insert ajax or local jQuery */
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
@leohxj
leohxj / addListener.js
Created October 10, 2013 02:11
事件侦听
function addListener(element, type, callback) {
if (element.addEventListener) element.addEventListener(type, callback);
else if (element.attachEvent) element.attachEvent('on' + type, callback);
}
@leohxj
leohxj / getAndroidVersion.js
Created October 18, 2013 08:57
判断 android version
function getAndroidVersion() {
var androidVersion = -1; // def value, for non-Android devices
var ua = navigator.userAgent.toLowerCase();
var androidIndex = ua.indexOf('android');
if(androidIndex != -1) {
var versionStartIndex = androidIndex + 8;
var versionEndIndex = ua.indexOf(';', versionStartIndex);
androidVersion = parseFloat(ua.slice(versionStartIndex, versionEndIndex));
@leohxj
leohxj / javascript_resources.md
Created October 22, 2013 01:53 — forked from jookyboi/javascript_resources.md
Here are a set of libraries, plugins and guides which may be useful to your Javascript coding.

Libraries

  • jQuery - The de-facto library for the modern age. It makes things like HTML document traversal and manipulation, event handling, animation, and Ajax much simpler with an easy-to-use API that works across a multitude of browsers.
  • Backbone - Backbone.js gives structure to web applications by providing models with key-value binding and custom events, collections with a rich API of enumerable functions, views with declarative event handling, and connects it all to your existing API over a RESTful JSON interface.
  • AngularJS - Conventions based MVC framework for HTML5 apps.
  • Underscore - Underscore is a utility-belt library for JavaScript that provides a lot of the functional programming support that you would expect in Prototype.js (or Ruby), but without extending any of the built-in JavaScript objects.
  • lawnchair - Key/value store adapter for indexdb, localStorage