Skip to content

Instantly share code, notes, and snippets.

View bh-lay's full-sized avatar
🏅
Github 认证工程师

剧中人 bh-lay

🏅
Github 认证工程师
View GitHub Profile
@bh-lay
bh-lay / TypeOf
Created October 30, 2014 06:04
get type of the variable
/**
* 判断对象类型
* string number array
* object function
* htmldocument
* undefined null
*/
function TypeOf(obj) {
return Object.prototype.toString.call(obj).match(/\s(\w+)/)[1].toLowerCase();
}
@bh-lay
bh-lay / isNum
Created October 30, 2014 06:09
check a variable is number include like number string
/**
* 检测是否为数字
* 兼容字符类数字 '23'
*/
function isNum(ipt){
return (ipt !== '') && (ipt == +ipt) ? true : false;
}
@bh-lay
bh-lay / each
Last active August 29, 2015 14:08
Traversal array or object
/**
* 遍历数组
*
*/
function each(arr,fn){
//检测输入的值
if(typeof(arr) == 'object' && typeof(fn) == 'function'){
var Length = arr.length;
if(Length && Length == +Length){
for(var i=0;i<Length;i++){
@bh-lay
bh-lay / stickyFooter.js
Last active August 29, 2015 14:13
stickyFooter
function stickyFooter($footer){
var $window = $(window);
//计算位置
function fix() {
$footer.css({
position: "static"
});
if ($window.height() < document.body.scrollHeight) {
$footer.css({
@bh-lay
bh-lay / isSameObj.js
Created June 14, 2016 06:23
判断两个对象是否相等
function isJSON( input ){
var returns = true;
try{
JSON.stringify( input )
} catch ( e ){
returns = false;
}
return returns;
}
function isSameObj( objA, objB ){
@bh-lay
bh-lay / isNaN.js
Last active August 4, 2016 10:32
判断输入值是否为NaN
// 判断输入值是否为NaN
function isNaN( input ){
return input !== input;
}
@bh-lay
bh-lay / LoadScript.js
Created December 25, 2016 15:41
简短的加载JS方法
/**
* 加载JS
*/
function LoadScript(url, callback){
var urls = typeof url === 'string' ? [url] : url;
if (!Array.isArray(urls)){
throw 'argument type error';
return;
@bh-lay
bh-lay / GCJTobaidu.js
Created December 25, 2016 16:25
各地图产品间的坐标转换
//GCJ-02转换BD-09
function GCJTobaidu($lat, $lng){
var $v = Math.PI * 3000.0 / 180.0;
var $x = $lng;
var $y = $lat;
var $z = Math.sqrt($x * $x + $y * $y) + 0.00002 * Math.sin($y * $v);
var $t = Math.atan2($y, $x) + 0.000003 * Math.cos($x * $v);
return {
@bh-lay
bh-lay / randomFlag.js
Created December 27, 2016 02:23
简单的随机生成唯一标识方法
var randomFlag = (new Date().getTime()*100000 + Math.ceil( Math.random() * 100000 )).toString(36);
@bh-lay
bh-lay / moveItems.js
Created December 27, 2016 09:16
数组中的常见操作
// 移动数组中指定索引的位置
function moveItems(arr, indexFrom, indexTo) {
arr.splice(indexTo, 0, arr.splice(indexFrom, 1)[0]);
return arr;
}
moveItems([0,1,2,3,4,5,6,7,8,9],0,7);