Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <section>
    <div class="grid">
        <div class="item" id="active">
            <h1>EyeDropper</h1>
            <p>点击颜色模块开启拾色器(吸管)模式获取当前光标位置颜色</p>
            <p>
                你当前所选的是:
                <mark id="name">颜色名</mark>
                <mark id="hex" style="text-decoration: underline;">HEX</mark>
            </p>
        </div>
        <div class="item" onclick="getColor(this)" style="background: Orange;">Orange</div>
        <div class="item" onclick="getColor(this)" style="background: BlueViolet;">BlueViolet</div>
        <div class="item" onclick="getColor(this)" style="background: Chartreuse;">Chartreuse</div>
        <div class="item" onclick="getColor(this)" style="background: DeepPink;">DeepPink</div>
        <div class="item" onclick="getColor(this)" style="background: ForestGreen;">ForestGreen</div>
        <div class="item" onclick="getColor(this)" style="background: GreenYellow;">GreenYellow</div>
        <div class="item" onclick="getColor(this)" style="background: Indigo;">Indigo</div>
        <div class="item" onclick="getColor(this)" style="background: LawnGreen;">LawnGreen</div>
        <div class="item" onclick="getColor(this)" style="background: Maroon;">Maroon</div>
        <div class="item" onclick="getColor(this)" style="background: olive;">olive</div>
        <div class="item" onclick="getColor(this)" style="background: OrangeRed;">OrangeRed</div>
        <div class="item" onclick="getColor(this)" style="background: WhiteSmoke;">
            <p>WhiteSmoke</p>
            <p>或移出工作区👉</p>
        </div>
    </div>
</section>
              
            
!

CSS

              
                html,body{
    margin: 0;
}
.grid{
    display: grid;
    grid-template-columns: 25vw 25vw 25vw 25vw ;
    grid-template-rows: 25vh 25vh 25vh 25vh; 
}
.grid .item:first-of-type{
    background-color: #ef342a;
    cursor: pointer;
    color: black;
    text-shadow: 0 0 0.2em rgb(23, 252, 61), 0 0 0.2em rgb(36, 223, 19),0 0 0.2em rgb(0, 255, 85);
    grid-column: 1 / 3;
    grid-row: 1 / 3;
}
.grid .item:first-of-type::after{
    content: "";
}
.grid .item{
    position: relative;
    cursor: crosshair;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    border: 1px #f5f5f5 solid;
    font-size: 12px;
    padding: 1em;
    z-index: 0;
}
.grid .item::after{
    position: absolute;
    left: 0;
    top: 0;
    color: rgba(0,0,0,.05);
    content: "DeathGhost.cn";
    transform: scale(2) rotate(45deg);
    z-index: 1;
}
              
            
!

JS

              
                const active = document.querySelector('#active');
let colorName = document.querySelector('#name');
let colorHex = document.querySelector('#hex');
async function getColor(e) {
    if (!window.EyeDropper) {
        alert('浏览器不支持 EyeDropper!');
        return false;
    }
    const eyeDropper = new EyeDropper();
    const res = await eyeDropper.open().catch(error => console.warn('已取消!'));
    if (res) {
        // HEX
        active.style.background = res.sRGBHex;
        colorName.textContent = e.style.background;
        colorHex.textContent = res.sRGBHex;
    }
}
              
            
!
999px

Console