• 前端小知识


    1.正则去除空格

    function removeBlank(str) {
         return str.replace(/s+/g, '');
    }        

    2.倒计时写法

    function showTime(options) {
            var defaults = {
                end: 0,
                diffTime: 0,
                displayTpl: "{hour}:{minute}:{second}",
                el: $('.countDown'),
                callback: function () {
                }
            };
            var options = $.extend({}, defaults, options);
            var sec, s, m, h;
            options.end = new Date(options.end.toString().replace(/-/g, '/')).getTime();
    
            function eachTime() {
                if (sec >= 0) {
                    h = Math.floor(sec / (60 * 60));
                    m = Math.floor(sec % (60 * 60) / 60);
                    s = sec % (60 * 60) % 60;
                    h = h < 10 ? ('0' + h) : h;
                    m = m < 10 ? ('0' + m) : m;
                    s = s < 10 ? ('0' + s) : s;
                    options.el.html(options.displayTpl.replace("{hour}", h).replace("{minute}", m).replace("{second}", s));
                    sec--;
                }
            }
    
            var time = setInterval(function () {
                options.nowTime = new Date().getTime() + options.diffTime;
                sec = Math.floor((options.end - options.nowTime) / 1000);
    
                if (sec >= 0) {
                    eachTime();
                } else {
                    clearInterval(time);
                    options.callback && typeof (options.callback) === 'function' && options.callback();
                }
            }, 1000);
            return {
                 showTime: showTime
             }
        };

    3.控制台打印

    function log(tips, data) {
            console.log('````````````' + tips + '````````````');
            console.log(data);
            console.log('```````````````````````````````````');
            console.log('           ')
    }

    4.设置浏览器的基数

    var setWidth = function () {
            var w = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
            w = w > 640 ? 640 : w;
            w = w < 320 ? 320 : w;
            var htmlObj = $('html');
            var rem = w / 10 + 'px';
            htmlObj.css('font-size', rem);
    }
  • 相关阅读:
    pku2992 Divisors
    pku3090 Visible Lattice Points
    pku3615 Cow Hurdles
    禁止 verifier.dll 监控程序
    运行ogreSDK的samples
    #pragma pack(n) 啥时候可以不再忘记?
    游戏开发流程图。
    希望可以尽快的写篇自己的成果。
    windows与OS X下的std::string
    VS2008鼠标右键不灵敏,TFS的Local Path无法打开对应文件夹
  • 原文地址:https://www.cnblogs.com/wangtao-/p/10496060.html
Copyright © 2020-2023  润新知