UNPKG

vue-weui-expand

Version:

WeUI 的轻量级 js 封装

78 lines (71 loc) 2.31 kB
//优雅字符串拼接 function _Substitute(str, obj) { /// <summary>优雅字符串拼接</summary> /// <param name="str" type="string">格式字符串:你好{title},你是在{where}?</param> /// <param name="obj" type="Object">一个对象:obj = { title: "小陈", where: "中国" };</param> if (!(Object.prototype.toString.call(str) === '[object String]')) { return ''; } if (!(Object.prototype.toString.call(obj) === '[object Object]' && 'isPrototypeOf' in obj)) { return str; } return str.replace(/\{([^{}]+)\}/g, function (match, key) { var value = obj[key]; return (value !== undefined) ? '' + value : ''; }); } ///是否闰年 let leap = function isLeapYear(Year) { if ((Year % 4 == 0 && Year % 100 != 0) || Year % 400 == 0) { return true; } else { return false; } }; //年的月份最大天数 let lastDay = function(yerar, month) { let e = 0; if ( month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12 ) { e = 31; } else if (leap(yerar) && month == 2) { e = 29; } else if (month == 2) { e = 28; } else { e = 30; } return e; }; //获取滚动条当前的位置 function getScrollTop() { var scrollTop = 0; if(document.documentElement && document.documentElement.scrollTop) { scrollTop = document.documentElement.scrollTop; } else if(document.body) { scrollTop = document.body.scrollTop; } return scrollTop; } //获取当前可视范围的高度 function getClientHeight() { var clientHeight = 0; if(document.body.clientHeight && document.documentElement.clientHeight) { clientHeight = Math.min(document.body.clientHeight, document.documentElement.clientHeight); } else { clientHeight = Math.max(document.body.clientHeight, document.documentElement.clientHeight); } return clientHeight; } //获取文档完整的高度 function getScrollHeight() { return Math.max(document.body.scrollHeight, document.documentElement.scrollHeight); } export {_Substitute,leap,lastDay,getScrollTop,getClientHeight,getScrollHeight}