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

Save Automatically?

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

              
                <div class="inbox">
    <label class="item">
        <input type="checkbox">
        <p>This is an inbox layout.</p>
    </label>
    <label class="item">
        <input type="checkbox">
        <p>Check one item</p>
    </label>
    <label class="item">
        <input type="checkbox">
        <p>Hold down your Shift key</p>
    </label>
    <label class="item">
        <input type="checkbox">
        <p>Check a lower item</p>
    </label>
    <label class="item">
        <input type="checkbox">
        <p>Everything inbetween should also be set to checked</p>
    </label>
    <label class="item">
        <input type="checkbox">
        <p>Try do it with out any libraries</p>
    </label>
    <label class="item">
        <input type="checkbox">
        <p>Just regular JavaScript</p>
    </label>
    <label class="item">
        <input type="checkbox">
        <p>Good Luck!</p>
    </label>
    <label class="item">
        <input type="checkbox">
        <p>Don't forget to tweet your result!</p>
    </label>
</div>
              
            
!

CSS

              
                html {
    font-family: sans-serif;
    background: #ffc600;
}

.inbox {
    max-width: 400px;
    margin: 50px auto;
    background: white;
    border-radius: 5px;
    box-shadow: 10px 10px 0 rgba(0, 0, 0, 0.1);
}

.item {
    display: flex;
    align-items: center;
    border-bottom: 1px solid #F1F1F1;
     user-select: none; 
        -ms-user-select: none; 
       -moz-user-select: none;
    -webkit-user-select: none;
}

.item:last-child {
    border-bottom: 0;
}

input:checked + p {
    background: #F9F9F9;
    text-decoration: line-through;
}

input[type="checkbox"] {
    margin: 20px;
}

p {
    margin: 0;
    padding: 20px;
    transition: background 0.2s;
    flex: 1;
    font-family: 'helvetica neue';
    font-size: 20px;
    font-weight: 200;
    border-left: 1px solid #D1E2FF;
}

.details {
    text-align: center;
    font-size: 15px;
}

              
            
!

JS

              
                // 待解決
/**
 * 1. 按住 shift 會選取文字
**/

// STEP1: 選擇並監聽所以的 checkbox

const checkboxs = document.querySelectorAll('.inbox input[type="checkbox"]');
checkboxs.forEach(checkbox => checkbox.addEventListener("click", checkHandler));

let prevCheck;
function checkHandler(e) {

    let inBetween = false;

    if (e.shiftKey && e.target.checked) {
        checkboxs.forEach(checkbox => {
            if (checkbox.parentNode === e.target.parentNode.nextElementSibling || checkbox.parentNode === prevCheck) {
                /**
                 * 這裡是 inBetween 的開關,
                 * 第一次碰到會開啟,第二次碰到會關閉
                **/
                inBetween = !inBetween;
            }
            console.log("inBetween", checkbox, inBetween);    
            if (inBetween) {
                checkbox.checked = true;
            }
        });
    }
    if (this.checked) {
        prevCheck = e.target.parentNode; // 記住使用者上一次點擊的 checkbox
        console.log("---------------prevCheck", prevCheck);
    }
}

              
            
!
999px

Console