Skip to content

Instantly share code, notes, and snippets.

View Alex-xd's full-sized avatar

Alex Alex-xd

View GitHub Profile
@Alex-xd
Alex-xd / oo.js
Created September 10, 2016 02:51
一段代码解释JavaScript面向对象
作者:颜海镜
链接:https://zhuanlan.zhihu.com/p/22388052
来源:知乎
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
(function(){
//私有静态成员
var user = "";
//私有静态方法
@Alex-xd
Alex-xd / 1.js
Created September 13, 2016 05:01
找出下面代码的规律并且编写一个函数,转换特定的整数到对应的字符串。 1 => A,2 => B,3 => C,...,26 => Z,27 => AA,28 => AB,29 => AC,...,52 => AZ,53 => BA,...
function convert(num){
var result = ""
while(num){
result = String.fromCharCode( --num % 26 + 65) + result
num = Math.floor(num / 26)
}
return result
}
@Alex-xd
Alex-xd / _typeof.js
Created September 20, 2016 08:52
最有用的JS类型检测!
function _typeof(something){
return Object.prototype.toString.call(something).slice(8,-1);
}
$(document.links).filter(function() {
return this.hostname != window.location.hostname;
}).attr('target', '_blank');
<style type="text/css">
/*IE 10 */
select::-ms-expand{
display: none;
}
select{
/* Chrome */
-webkit-appearance: none;
/* Firefox */
-moz-appearance: none;
/*
DOM结构说明:
ul.avatar-list
li
img.avatar
li
img.avatar
*/
.avatar-list > li:nth-child(3n+2) img {
border-top-left-radius: 84%;
@Alex-xd
Alex-xd / requestAnimationFrame.js
Last active December 30, 2016 17:44
JS动画
(function() {
var lastTime = 0;
var vendors = ['webkit', 'moz'];
for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame'];
window.cancelAnimationFrame =
window[vendors[x]+'CancelAnimationFrame'] || window[vendors[x]+'CancelRequestAnimationFrame'];
}
if (!window.requestAnimationFrame)
@Alex-xd
Alex-xd / escapeHTML.js
Created January 6, 2017 15:51
转义HTML
function escapeHTML(a) {
a = "" + a;
return a.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;");
;
}
function debounce(dom, event, fn, timeout) {
var timeout = timeout || 3; // 默认延迟3s内点击无效
var timer = null;
// cornor cases
if (!dom || !event || !(event in dom) || typeof fn !== 'function') {
return
}
dom.addEventListener(event, function () {
var _this = this;
//2.处理毫秒级的时间
$.extend({
handleTime:function(times){
var nowTime = new Date(times),
year = nowTime.getFullYear(),
month = nowTime.getMonth(),
day = nowTime.getDate();
return year+'.'+month+"."+day;