Skip to content
This repository has been archived by the owner on Jan 28, 2023. It is now read-only.

简化建议 #1

Open
7est opened this issue Dec 16, 2021 · 0 comments
Open

简化建议 #1

7est opened this issue Dec 16, 2021 · 0 comments

Comments

@7est
Copy link

7est commented Dec 16, 2021

将css上传任意开黑啦频道,借开黑啦的cdn在线加载css。
再写一个js,大概可以这样

function includeCss(filename) {
    var head = document.getElementsByTagName('head')[0];
    var link = document.createElement('link');
    link.href = filename;
    link.rel = 'stylesheet';
    link.type = 'text/css';
    head.appendChild(link)
}

function addGlobalStyle(css) {
    var head, style;
    head = document.getElementsByTagName('head')[0];
    if (!head) {
        return;
    }
    style = document.createElement('style');
    style.innerHTML = css;
    head.appendChild(style);
}

function bg(url) {
    addGlobalStyle('*{--background-url: url("' + url + '");}')
}

includeCss('css的地址')

上传此js也到开黑啦任意频道。
在index.htm的最后,加上一句<script>调用这个js即可,要改背景还可以再来一句<script>bg('图片url')</script>

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant