Skip to content

Instantly share code, notes, and snippets.

View alex1504's full-sized avatar
🏀
On the way.

Zerui Hu alex1504

🏀
On the way.
  • South China Agricultural University
  • ShenZhen,GuangDong,China
View GitHub Profile
@alex1504
alex1504 / meta.html
Last active May 26, 2017 07:16
Useful meta in mobile browser
<html>
<head>
<!-- 声明文档使用的字符编码 -->
<meta charset='utf-8'>
<!-- 优先使用 IE 最新版本和 Chrome -->
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
<!-- 页面描述 -->
<meta name="description" content="不超过150个字符"/>
<!-- 页面关键词 -->
<meta name="keywords" content=""/>
@alex1504
alex1504 / vanilla-vs-jquery.md
Last active May 26, 2017 07:17 — forked from liamcurry/gist:2597326
原生JS与jQuery实现方式对比

Moving from jQuery

Events

// jQuery
$(document).ready(function() {
  // code
})
@alex1504
alex1504 / rem-auto-resize.md
Last active May 26, 2017 09:02
rem自适应手机屏幕方案

自适应脚本方案(比例:1rem=100px)

(function(doc, win) {
    var docEl = doc.documentElement,
        resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
        recalc = function() {
            var clientWidth = docEl.clientWidth;
            if (!clientWidth) return;
            if (clientWidth >= 640) {
                docEl.style.fontSize = '100px';
@alex1504
alex1504 / detect-font.js
Last active May 26, 2017 09:34
判断浏览器是否存在某种字体
(function() {
/**
* 根据测试字体与基准字体拼接后字体的宽高 和 原来基准字体的宽高进行对比,若不同,则说明测试字体存在
*/
var Detector = function() {
// 传入的字体会和下面三种字体作比较
var baseFonts = ['monospace', 'sans-serif', 'serif'];
// 使用m和w作为测试字符因为它们占据最大宽度
var testString = "mmmmmmmmmmlli";
@alex1504
alex1504 / node-proxy-request.js
Created May 26, 2017 09:47
Node代理访问接口解决跨域问题
var express = require('express');
var app = express();
var http = require('http');
var httpServer = http.Server(app);
app.all('*', function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "X-Requested-With");
res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
res.header("X-Powered-By",' 3.2.1');
@alex1504
alex1504 / normalize.css
Last active May 31, 2017 02:55
样式初始化
/* ============================== START normalize.css ==============================*/
/*! normalize.css v7.0.0 | MIT License | github.com/necolas/normalize.css */
/**
* 1. Correct the line height in all browsers.
* 2. Prevent adjustments of font size after orientation changes in
* IE on Windows Phone and in iOS.
*/
html {
@alex1504
alex1504 / DetectBrowser.js
Created June 7, 2017 04:02
判断浏览器类型
function isSafari() {
return navigator.userAgent.indexOf('Safari') > 0 &&
navigator.userAgent.indexOf('Chrome') < 0;
}
function isIe() {
return navigator.userAgent.indexOf('MSIE') > 0;
;
}
@alex1504
alex1504 / gulpfile-1.js
Last active June 22, 2017 03:54
1、gulp重命名及精灵图生成 2、css、js压缩合并
var gulp = require('gulp');
var concat = require('gulp-concat');
var cleancss = require('gulp-clean-css');
var uglify = require('gulp-uglify');
var autoprefixer = require('gulp-autoprefixer');
gulp.task('css',function(){
return gulp.src('css/*.css')
.pipe(concat('style.min.css'))
@alex1504
alex1504 / jquery-pop-options.js
Last active June 22, 2017 10:10
jQuery options pop
$.extend({
popOptions: function(params) {
var defaults = {
title: "标题",
options: [{
name: "选项一",
onClick: function() {}
},
{
name: "选项二",
@alex1504
alex1504 / detect-img-light.js
Created July 19, 2017 10:10
js判断图片的明亮度
/* This function will convert each color to gray scale and return average of all pixels, so final value will be between 0 (darkest) and 255 (brightest) */
function getImageLightness(imageSrc,callback) {
var img = document.createElement("img");
img.src = imageSrc;
img.style.display = "none";
document.body.appendChild(img);
var colorSum = 0;
img.onload = function() {