This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.addEventListener('pageshow', function(e) { | |
if (e.persisted) {// 从缓存加载 | |
//... | |
} | |
}, false); | |
//jquery中没有这个对象,需要用原生事件对象 | |
$(window).bind("pageshow", function(event) { | |
if (event.originalEvent.persisted) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var _isSupport = function(prop){ | |
var div = document.createElement('div'), | |
vendors = 'Khtml O Moz Webkit'.split(' '), | |
len = vendors.length; | |
if ( prop in div.style ) return true; | |
if ('-ms-' + prop in div.style) return true; | |
prop = prop.replace(/^[a-z]/, function(val) { | |
return val.toUpperCase(); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//your object | |
var o = { | |
foo:"bar", | |
arr:[1,2,3], | |
subo: { | |
foo2:"bar2" | |
} | |
}; | |
//called with every property and it's value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//设置URL参数的方法 | |
function setParmsValue(parms, parmsValue) { | |
var urlstrings = document.URL; | |
var args = GetUrlParms(); | |
var values = args[parms]; | |
//如果参数不存在,则添加参数 | |
if (values == undefined) { | |
var query = location.search.substring(1); //获取查询串 | |
//如果Url中已经有参数,则附加参数 | |
if (query) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getEnv(){ | |
var ua = navigator.userAgent.toLowerCase(); | |
if(/micromessenger(\/[\d\.]+)*/.test(ua)){ | |
return "weixin" | |
}else if(/qq\/(\/[\d\.]+)*/.test(ua) || /qzone\//.test(ua)){ | |
return "qq"; | |
}else{ | |
return "web"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var arr = [ | |
{name:'hdj', age:28}, | |
{name:'yim', age:25}, | |
{name:'hdq', age:26},{name:'hdq', age:22},{name:'hdq', age:555},{name:'hdq', age:1111},{name:'hdq', age:99} | |
]; | |
function arrSortByField(arr, field,order,primer){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//source:http://www.webhek.com/vendor-prefix/ | |
//return: {dom: "WebKit", lowercase: "webkit", css: "-webkit-", js: "Webkit"} | |
var prefix = (function () { | |
var styles = window.getComputedStyle(document.documentElement, ''), | |
pre = (Array.prototype.slice | |
.call(styles) | |
.join('') | |
.match(/-(moz|webkit|ms)-/) || (styles.OLink === '' && ['', 'o']) | |
)[1], | |
dom = ('WebKit|Moz|MS|O').match(new RegExp('(' + pre + ')', 'i'))[1]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function $transJson2str(o) { | |
if (o == undefined) { | |
return ""; | |
} | |
var r = []; | |
if (typeof o == "string") return "\"" + o.replace(/([\"\\])/g, "\\$1").replace(/(\n)/g, "\\n").replace(/(\r)/g, "\\r").replace(/(\t)/g, "\\t") + "\""; | |
if (typeof o == "object") { | |
if (o.nodeName){ | |
r.push(["document node", "nodeName:"+o.nodeName, "id:"+o.id, "class:"+o.className].join('-')); | |
r = "{" + r.join() + "}"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function parseJSON( data ) { | |
var // JSON RegExp | |
rvalidchars = /^[\],:{}\s]*$/ | |
, rvalidbraces = /(?:^|:|,)(?:\s*\[)+/g | |
, rvalidescape = /\\(?:["\\\/bfnrt]|u[\da-fA-F]{4})/g | |
, rvalidtokens = /"[^"\\\r\n]*"|true|false|null|-?(?:\d+\.|)\d+(?:[eE][+-]?\d+|)/g | |
; | |
if ( window.JSON && window.JSON.parse ) { | |
return window.JSON.parse( data ); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 时间倒数吸顶 | |
$.fn.smartFloat = function() { | |
var position = function(element) { | |
var top = element.position().top, pos = element.css("position"); | |
$(window).scroll(function() { | |
var scrolls = $(this).scrollTop(); | |
if (scrolls > top) { | |
if (window.XMLHttpRequest) { | |
element.css({ | |
position: "fixed", |
NewerOlder