Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ 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

              
                .player
    video.player__video.viewer(src="http://www.html5videoplayer.net/videos/toystory.mp4")
    .player__controls
        .progress
            .progress__filled
        button.player__button.toggle(title="Toggle Play") ►
        input.player__slider(type="range" name="volume" min="0" max="1" step="0.05" value="0.5")
        input.player__slider(type="range" name="playbackRate" min="0.5" max="2" step="0.1" value="1")
        button.player__button(data-skip="-10") « 10s
        button.player__button(data-skip="25") 25s »
    
              
            
!

CSS

              
                html {
    box-sizing: border-box;
}

*, *:before, *:after {
    box-sizing: inherit;
}

body {
    padding: 0;
    display: flex;
    background: #7A419B;
    min-height: 100vh;
    background: linear-gradient(135deg, #7c1599 0%, #921099 48%, #7e4ae8 100%);
    background-size: cover;
    align-items: center;
    justify-content: center;
}

.player {
    max-width: 750px;
    border: 5px solid rgba(0, 0, 0, 0.2);
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.2);
    position: relative;
    font-size: 0;
    overflow: hidden;
}

.player__video {
    width: 100%;
}

/**
 * .player__button 將 button reset 
**/
.player__button {
    background: none;
    border: 0;
    line-height: 1;
    color: white;
    text-align: center;
    outline: 0;
    padding: 0;
    cursor: pointer;
    max-width: 50px;
}

.player__button:focus {
    border-color: #ffc600;
}

.player__slider {
    width: 10px;
    height: 30px;
}

.player__controls {
    display: flex;
    position: absolute;
    bottom: 0;
    width: 100%;
    transform: translateY(100%) translateY(-5px);
    transition: all .3s;
    flex-wrap: wrap;
    background: rgba(0, 0, 0, 0.1);
}

.player:hover .player__controls {
    transform: translateY(0);
}

.player:hover .progress {
    height: 15px;
}

.player__controls > * {
    flex: 1;
}

.progress {
    flex: 10;
    position: relative;
    display: flex;
    flex-basis: 100%;
    height: 5px;
    transition: height 0.3s;
    background: rgba(0, 0, 0, 0.5);
    cursor: ew-resize;
}

.progress__filled {
    width: 50%;
    background: #ffc600;
    flex: 0;
    flex-basis: 5%;
}

/* unholy css to style input type="range" */

input[type=range] {
    -webkit-appearance: none;
    background: transparent;
    width: 100%;
    margin: 0 5px;
}
input[type=range]:focus {
    outline: none;
}
input[type=range]::-webkit-slider-runnable-track {
    width: 100%;
    height: 8.4px;
    cursor: pointer;
    box-shadow: 1px 1px 1px rgba(0, 0, 0, 0), 0 0 1px rgba(13, 13, 13, 0);
    background: rgba(255, 255, 255, 0.8);
    border-radius: 1.3px;
    border: 0.2px solid rgba(1, 1, 1, 0);
}
input[type=range]::-webkit-slider-thumb {
    box-shadow: 0 0 0 rgba(0, 0, 0, 0), 0 0 0 rgba(13, 13, 13, 0);
    height: 15px;
    width: 15px;
    border-radius: 50px;
    background: #ffc600;
    cursor: pointer;
    -webkit-appearance: none;
    margin-top: -3.5px;
    box-shadow: 0 0 2px rgba(0, 0, 0, 0.2);
}
input[type=range]:focus::-wefbkit-slider-runnable-track {
    background: #bada55;
}
input[type=range]::-moz-range-track {
    width: 100%;
    height: 8.4px;
    cursor: pointer;
    box-shadow: 1px 1px 1px rgba(0, 0, 0, 0), 0 0 1px rgba(13, 13, 13, 0);
    background: #ffffff;
    border-radius: 1.3px;
    border: 0.2px solid rgba(1, 1, 1, 0);
}
input[type=range]::-moz-range-thumb {
    box-shadow: 0 0 0 rgba(0, 0, 0, 0), 0 0 0 rgba(13, 13, 13, 0);
    height: 15px;
    width: 15px;
    border-radius: 50px;
    background: #ffc600;
    cursor: pointer;
}

              
            
!

JS

              
                /**
 * 選取所有相關元素
 **/
const player = document.querySelector(".player");
const video = player.querySelector(".viewer");
const progress = player.querySelector(".progress");
const progressBar = player.querySelector(".progress__filled");
const toggle = player.querySelector(".toggle");
const skipButtons = player.querySelectorAll("[data-skip]");
const ranges = player.querySelectorAll(".player__slider");

/**
 * 播放影片相關函式
**/

// 播放或暫停影片
function togglePlay() {
    let playOrPause = video.paused ? "play" : "pause";
    video[playOrPause](); // video.play() or video.pause()
}

// 切換播放按鈕 icon
function switchPlayButtonIcon () {
    let icon = this.paused ? '►' : '❚ ❚';
    toggle.textContent = icon
}

video.addEventListener('click', togglePlay)
video.addEventListener('play', switchPlayButtonIcon)
video.addEventListener('pause', switchPlayButtonIcon)
toggle.addEventListener('click', togglePlay)

/**
 * 快轉回播相關函式
**/
function skip (e) {
    video.currentTime += Number(e.target.dataset.skip)
}
skipButtons.forEach(skipButton => {
    skipButton.addEventListener('click', skip)
})

/**
 * 調整音量和播放速度相關函式
**/
function handleRangeUpdate (e) {
    video[e.target.name] = e.target.value
}
ranges.forEach(rangeInput => {
    rangeInput.addEventListener('input', handleRangeUpdate)
})

/**
 * 進度條相關函式
**/
// 顯示當前播放進度
function showCurrentProgress () {
    let progressPercent = (video.currentTime / video.duration) * 100
    // 利用 flex-basis 改變 progressbar 長度
    progressBar.style.flexBasis = progressPercent + '%'
}
// 當 video.currentTime 改變時會觸發 timeupdate
video.addEventListener('timeupdate', showCurrentProgress)

// 點擊進度條改變當前播放進度
function changeCurrentProgress (e) {
    // console.log('offsetParent', e.target.offsetParent)
    let timeAtProgressBar = (e.offsetX / progress.offsetWidth) * video.duration
    video.currentTime = Number(timeAtProgressBar)
}
progress.addEventListener('click', changeCurrentProgress)


              
            
!
999px

Console