鍍金池/ 問(wèn)答/ HTML問(wèn)答

這個(gè)彈幕滾動(dòng)的動(dòng)畫(huà)效果一般都是定時(shí)函數(shù)setInterval做的,當(dāng)你停下的時(shí)候就cleanInterval就行了,
動(dòng)畫(huà)函數(shù)的內(nèi)容類(lèi)似輪播,滾動(dòng)播放那些插件的內(nèi)容,修改的都是當(dāng)前字幕的dom對(duì)象樣式,所以刪除定時(shí)的時(shí)候彈幕就停下了

夏木 回答

代碼亂七八糟的。

js 里沒(méi)有大數(shù)字。超過(guò) 整數(shù)就是浮點(diǎn)數(shù)。浮點(diǎn)不精確。

php有bcmath,你要算就全用 bcmath 來(lái)算,中間有個(gè)整數(shù)與&,和位移<<,是怎么回事?

遲月 回答

使用數(shù)組解構(gòu)似乎更方便。

let [, {children: [{children}]}] = json
let index = children.findIndex(obj => obj.name === 'a1')
children[0].expand = true

是不是很簡(jiǎn)單,捂臉逃走。

練命 回答

可以看下這篇文章,大概意思是命名函數(shù)表達(dá)式NFE的名字是存在一個(gè)輔助特殊對(duì)象(auxiliary special object)中的,而且是只讀的,所以在非嚴(yán)格模式下修改會(huì)靜默失敗,如果這段函數(shù)內(nèi)部在嚴(yán)格模式下運(yùn)行會(huì)報(bào)錯(cuò)Uncaught TypeError: Assignment to constant variable.,其他答案中說(shuō)的c被定義成全局是不對(duì)的,可以試一下把console.log(c)改成console.log(window.c)也是undefined。

凹凸曼 回答

border-radius:3px

練命 回答

@sanzado 兄弟你們有定位出這個(gè)問(wèn)題嗎,我現(xiàn)在也遇到這個(gè)問(wèn)題了。

玄鳥(niǎo) 回答

你是說(shuō)event.target可能是titlesub?
如果是這個(gè)意思的話(huà),這跟vue和jquery都沒(méi)關(guān)系。
取綁定事件的元素的話(huà)是用event.currentTarget
自己看,別用self,跟vue沒(méi)關(guān)系,就是event.targetevent.currentTarget的區(qū)別

https://jsfiddle.net/o6xox400/3/

浪婳 回答

寫(xiě)了自定義規(guī)則,前面兩個(gè)就不要了,也不要message了:

productTitle: [
    { validator: (rule, value, callback)=>{
        if(!value){
            callback(new Error('請(qǐng)?zhí)顚?xiě)商品標(biāo)題'))
        }
        if(value.length>25){
            callback(new Error('商品標(biāo)題最多不超過(guò)25個(gè)'))
        }
        callback()
    }, trigger: ['change', 'blur'] }
]
離夢(mèng) 回答

直接寫(xiě)成絕對(duì)路徑便可:/static/img/head.PNG

解決方法:

1、轉(zhuǎn)換思路,左邊放echarts圖,右邊放一個(gè)獨(dú)立的div
2、在echarts的配置里面,作出以下修改:
圖片描述

修改一下legend組件的配置,添加定位

臭榴蓮 回答

session可以存數(shù)組的,沒(méi)登錄你就先給他扔session里面,離開(kāi)頁(yè)面就消失了;如果登錄了你就把他同步到登錄的這個(gè)人的信息里面

悶油瓶 回答

這些基本都是模塊化方案,實(shí)際上自己頁(yè)很容易寫(xiě)出模塊化的原理
webpack

(function(modulesArr) {
    var rootModule = {};
    function __require__(id) {
        if (rootModule[id]) {
            return rootModule[id].exports;
        }
        var currentModule = modulesArr[id];
        var module = {
            id,
            exports: {}
        };
        currentModule.call(module.exports, module.exports, module, __require__);
        currentModule[id] = module;
        return module.exports;
    }
    return __require__(0);
})([
    function(exports, module, require) {
        var m1 = require(1);
        console.log(m1);
    },
    function(exports, module, require) {
        exports.msg = 'Hello World';
        var m2 = require(2);
        m2();
    },
    function(exports, module, require) {
        module.exports = function() {
            var str = 'Hello World';
            console.log(str);
            return str;
        };
    }
]);

我自己實(shí)現(xiàn)的browser端模塊化

(function(global) {
    'use strict';
    var errMsg = Math.random().toString(32).substr(2);
    var rootModule = {};
    function ModuleCtor(id) {
        if (!this || this.__proto__ !== ModuleCtor.prototype) {
            return new ModuleCtor(id);
        }
        this.id = id;
        this.exports = {};
        this.loaded = !1;
    }

    function define(id, fn) {
        if (typeof id === 'function') {
            fn = id;
            id = document.currentScript
                ? document.currentScript.src
                : Math.random()
                      .toString(32)
                      .substr(2);
        }
        if (typeof id !== 'string') {
            id = '' + id;
        }
        var module = ModuleCtor(id);
        exec();
        function __require__(src) {
            if (rootModule[src] && rootModule[src].__proto__ === ModuleCtor.prototype) {
                return rootModule[src].exports;
            }
            loadScript(src, function() {
                exec();
            });
            throw new Error(errMsg);
        }
        function exec() {
            try {
                fn.call(module.exports, module.exports, module, __require__);
                module.loaded = !0;
                rootModule[id] = module;
            } catch (err) {
                if (err.message !== errMsg) {
                    throw err;
                }
            }
        }
    }

    function loadScript(src, callback) {
        var script = document.createElement('script');
        script.src = src;
        script.onload = function() {
            callback && callback(src);
        };
        document.body.appendChild(script);
        return script;
    }
    global.define = define;
})(window);

本質(zhì)都是js沒(méi)有模塊,所以我們就想到全局暴露一個(gè)rootModule對(duì)象,每一個(gè)鍵都是一個(gè)模塊,exports對(duì)象是依賴(lài)的暴露。
如a.js

    module.exports = 'Hello World';

b.js

    var chars = require('./a');
    process.stdout.write(chars + '\n'); // Hello World

但是我們?cè)趺磳?shí)現(xiàn)呢,(一)編譯:如webpack,(二)暴露一個(gè)函數(shù),如requirejs、seajs。


webpack 可以配置 output libraryTarget: 'umd', library: 'globalVarName' 打題主說(shuō)的這種umd包,兼容瀏覽器,requirejs,node環(huán)境。


另外我還是忍不住吐槽一下seajs的垃圾,一個(gè)文件的多個(gè)require發(fā)請(qǐng)求時(shí)沒(méi)有順序之分,字符串正則來(lái)分析依賴(lài)。。。如果jQuery的plugin依賴(lài)jQuery,需要對(duì)jQueryplugin改一下代碼討個(gè)套個(gè)客,不能直接想requirejs直接在config中聲明依賴(lài)。垃圾。當(dāng)然我自己寫(xiě)的模塊加載更垃圾,連依賴(lài)都不分析。多try幾次必然成功。

瘋子范 回答
  1. 最后的結(jié)果沒(méi)區(qū)別。但是如果你對(duì)時(shí)間要求很高的話(huà),我建議是服務(wù)端渲染,比如頁(yè)面緩存。而如果要求不是太高的話(huà),我更傾向于前端渲染(開(kāi)發(fā)方便很多),SEO可以通過(guò)ua返回一個(gè)完整頁(yè)面,不是太大的問(wèn)題。
  2. 這樣前端就不用關(guān)心后端服務(wù),不用發(fā)送一堆請(qǐng)求然后組合出需要的視圖數(shù)據(jù),這部分都交到node上做,后端變更也只需要同時(shí)更新node服務(wù)。
  3. 短板暫時(shí)沒(méi)想到。等大佬指出。

補(bǔ)充

看到樓下的回答想起了耗子老師的一篇文章分布式系統(tǒng)架構(gòu)的冰與火
問(wèn)題3的邏輯大致相同

圖片描述

枕邊人 回答
改變前端pug、less、js文件后,怎么自動(dòng)刷新前端頁(yè)面?
  1. 自動(dòng)更新和熱更新不是同一個(gè)問(wèn)題。
  2. 這不只是一個(gè)前端自動(dòng)更新的問(wèn)題,模板數(shù)據(jù)肯定是跟后端數(shù)據(jù)走的。所以這問(wèn)題就變成了前后端如何自動(dòng)更新。
  3. 可以用gulp監(jiān)控文件,gulp-nodemon做后端自動(dòng)重啟,gulp-livereload做前端的自動(dòng)更新。