Skip to content

Instantly share code, notes, and snippets.

View jtyjty99999's full-sized avatar

Adams jtyjty99999

  • Tencent
  • Shenzhen China
View GitHub Profile
@jtyjty99999
jtyjty99999 / gist:9521482
Created March 13, 2014 03:27
鼠标移动方向
$(".overlayLink").bind("mouseenter mouseleave",function(e){
/** the width and height of the current div **/
var w = $(this).width();
var h = $(this).height();
/** calculate the x and y to get an angle to the center of the div from that x and y. **/
/** gets the x value relative to the center of the DIV and "normalize" it **/
var x = (e.pageX - this.offsetLeft - (w/2)) * ( w > h ? (h/w) : 1 );
var y = (e.pageY - this.offsetTop - (h/2)) * ( h > w ? (w/h) : 1 );
@jtyjty99999
jtyjty99999 / gist:9087540
Created February 19, 2014 07:28
切换多语言
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
<style>
[data-i18n="hello"]:before {
content: "Hello Maksim!";
}
@jtyjty99999
jtyjty99999 / gist:8877103
Created February 8, 2014 05:28
利用xhr2得到文件,转为bolb存储到localstorage中
// Getting a file through XMLHttpRequest as an arraybuffer and creating a Blob
var rhinoStorage = localStorage.getItem("rhino"),
rhino = document.getElementById("rhino");
if (rhinoStorage) {
// Reuse existing Data URL from localStorage
rhino.setAttribute("src", rhinoStorage);
}
else {
// Create XHR, Blob and FileReader objects
var xhr = new XMLHttpRequest(),
@jtyjty99999
jtyjty99999 / gist:8862498
Created February 7, 2014 13:18
测试输入法事件composition
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<input type="text" name="" id="hello">
<script>
var keys = {
backspace: 8,
tab: 9,
enter: 13,
'return': 13,
shift: 16,
'⇧': 16,
control: 17,
ctrl: 17,
'⌃': 17,
@jtyjty99999
jtyjty99999 / gist:8862415
Last active August 29, 2015 13:56
彩蛋制造器
感觉cheet.js挺有意思的,制造页面彩蛋,随便写了一个
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<script>
  1. Plain Strings (207): foo
  2. Anchors (208): k$
  3. Ranges (202): ^[a-f]*$
  4. Backrefs (201): (...).*\1
  5. Abba (169): ^(.(?!(ll|ss|mm|rr|tt|ff|cc|bb)))*$|^n|ef
  6. A man, a plan (177): ^(.)[^p].*\1$
  7. Prime (286): ^(?!(..+)\1+$)
  8. Four (199): (.)(.\1){3}
  9. Order (198): ^[^o].....?$
  10. Triples (507): (^39|^44)|(^([0369]|([147][0369]*[258])|(([258]|[147][0369]*[147])([0369]*|[258][0369]*[147])([147]|[258][0369]*[258])))*$)