1234567891011121314151617181920212223242526272829303132333435363738394041 |
- (function(doc, win) {
- var docEl = doc.documentElement,
- resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
- recalc = function() {
- var clientWidth = docEl.clientWidth;
- if(!clientWidth) return;
- if(clientWidth >= 1080) {
- docEl.style.fontSize = '100px';
- } else {
- docEl.style.fontSize = 100 * (clientWidth / 750) + 'px';
- }
- };
- if(!doc.addEventListener) return;
- win.addEventListener(resizeEvt, recalc, false);
- doc.addEventListener('DOMContentLoaded', recalc, false);
- var docEl = document.documentElement;
- var clientWidth = docEl.clientHeight;
- })(document, window);
- function toThousands (num, decimal) {
- if (decimal) {
- num = formatDecimal(num, decimal)
- }
- return num.toString().replace(/\d+/, function (n) { // 先提取整数部分
- return n.replace(/(\d)(?=(\d{3})+$)/g, function ($1) {
- return $1 + ','
- })
- })
- }
- function formatDecimal (num, decimal) {
- num = num.toString()
- const index = num.indexOf('.')
- if (index !== -1) {
- num = num.substring(0, decimal + index + 1)
- } else {
- num = num.substring(0)
- }
- return parseFloat(num).toFixed(decimal)
- }
|