Skip to content

Instantly share code, notes, and snippets.

View titanew's full-sized avatar

Titane w titanew

View GitHub Profile
@titanew
titanew / autoplay-audio-ios.html
Created May 19, 2017 03:28 — forked from ufologist/autoplay-audio-ios.html
在 iOS 微信浏览器中自动播放 HTML5 audio(音乐) 的正确方式
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<title>Auto play html audio in iOS WeChat InAppBrowser the right way</title>
</head>
<body>
<h1>在 iOS 微信浏览器中自动播放 HTML5 audio(音乐) 的正确方式</h1>
<p>核心原理: 在微信的JS-API 中 play 一下 audio 即可达到自动播放的目的(应该是微信自己做了处理)</p>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
alert(1);
@titanew
titanew / Detecting focus of a browser window
Created October 24, 2014 09:30
Detecting focus of a browser window
function onBlur() {
document.body.className = 'blurred';
};
function onFocus(){
document.body.className = 'focused';
};
if (/*@cc_on!@*/false) { // check for Internet Explorer
document.onfocusin = onFocus;
document.onfocusout = onBlur;
@titanew
titanew / gulpfile.js
Last active August 29, 2015 14:04
gulpfile.js
var gulp = require('gulp');
var coffee = require('gulp-coffee');
var usemin = require('gulp-usemin');
var uglify = require('gulp-uglify');
var cssmin = require('gulp-minify-css');
var sass = require('gulp-sass');
var clean = require('gulp-clean');
var cheerio = require('gulp-cheerio');
var srcPath = {
@titanew
titanew / gist:6102368
Created July 29, 2013 05:52
IE版本判断
var _IE = (function() {
var v = 3,
div = document.createElement('div'),
all = div.getElementsByTagName('i');
while (
div.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i><![endif]-->',
all[0]);
return v > 4 ? v : false;
}());
@titanew
titanew / gist:6034381
Created July 19, 2013 01:20
图片的延迟加载
lazyLoad = (function() {
var map_element = {};
var element_obj = [];
var download_count = 0;
var last_offset = -1;
var doc_body;
var doc_element;
var lazy_load_tag;
function initVar(tags) {
@titanew
titanew / gist:6019524
Created July 17, 2013 10:46
拖动小工具
var EventUtil={
addHandler:function(element,type,handler){
if(element.addEventListener){
element.addEventListener(type,handler,false);
}else if(element.attachEvent){
element.attachEvent("on"+type,handler);
}else{
element["on"+type]=handler;
}
},
@titanew
titanew / gist:5734570
Created June 8, 2013 08:50
slide 幻灯
(function($) {
$.fn.slide = function(options) {
var defaults = {
speed: 5000 //ms
};
var opts = $.extend({}, defaults, options);
return this.each(function() {
var _this = $(this);
var _child = $("li", _this);
var _length = _child.size();
@titanew
titanew / gist:5726855
Last active December 18, 2015 04:39
小切换和小滚动。
(function($) {
//选项卡
$.fn.tab = function(options) {
var defaults = {
classname: "news-content",
speed: "100",
evt: "mouseover"
};
var opts = $.extend({}, defaults, options);
@titanew
titanew / gist:5718565
Created June 6, 2013 00:55
about cookie
(function() {
function getCookie(name) {
var cookie = document.cookie;
var s = removeBlanks(cookie);
var pairs = s.split(";");
for (var i = 0; i < pairs.length; i++) {
var pairSplit = pairs[i].split("=");
if (pairSplit.length > 1 && pairSplit[0] == name) {
return pairSplit[1];
}