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

              
                <div id="hero">
  <div id="output">
    <div id="progressBar"></div>
  </div>
  <div id="status">
    <div>
      <span class="show-leech">Downloading </span>
      <span class="show-seed">Seeding </span>
      <code>
        <a id="torrentLink" href="https://webtorrent.io/torrents/sintel.torrent">sintel.torrent</a>
      </code>
      <span class="show-leech"> from </span>
      <span class="show-seed"> to </span>
      <code id="numPeers">0 peers</code>. 
    </div>
    <div>
      <code id="downloaded"></code>
      of <code id="total"></code>
      — <span id="remaining"></span><br/>
      &#x2198;<code id="downloadSpeed">0 b/s</code>
      / &#x2197;<code id="uploadSpeed">0 b/s</code>
    </div>
  </div>
</div>
              
            
!

CSS

              
                #output video {
  width: 100%;
}
#progressBar {
    height: 5px;
    width: 0%;
    background-color: #35b44f;
    transition: width .4s ease-in-out;
}
body.is-seed .show-seed {
    display: inline;
}
body.is-seed .show-leech {
    display: none;
}
.show-seed {
    display: none;
}
#status code {
    font-size: 90%;
    font-weight: 700;
    margin-left: 3px;
    margin-right: 3px;
    border-bottom: 1px dashed rgba(255,255,255,0.3);
}

.is-seed #hero {
    background-color: #154820;
    transition: .5s .5s background-color ease-in-out;
}
#hero {
    background-color: #2a3749;
}
#status {
    color: #fff;
    font-size: 17px;
    padding: 5px;
}
a:link, a:visited {
    color: #30a247;
    text-decoration: none;
}
              
            
!

JS

              
                var torrentId = 'https://webtorrent.io/torrents/sintel.torrent'

var client = new WebTorrent()

// HTML elements
var $body = document.body
var $progressBar = document.querySelector('#progressBar')
var $numPeers = document.querySelector('#numPeers')
var $downloaded = document.querySelector('#downloaded')
var $total = document.querySelector('#total')
var $remaining = document.querySelector('#remaining')
var $uploadSpeed = document.querySelector('#uploadSpeed')
var $downloadSpeed = document.querySelector('#downloadSpeed')

// Download the torrent
client.add(torrentId, function (torrent) {

  // Stream the file in the browser
  torrent.files[0].appendTo('#output')

  // Trigger statistics refresh
  torrent.on('done', onDone)
  setInterval(onProgress, 500)
  onProgress()
  
  // Statistics
  function onProgress () {
    // Peers
    $numPeers.innerHTML = torrent.numPeers + (torrent.numPeers === 1 ? ' peer' : ' peers')

    // Progress
    var percent = Math.round(torrent.progress * 100 * 100) / 100
    $progressBar.style.width = percent + '%'
    $downloaded.innerHTML = prettyBytes(torrent.downloaded)
    $total.innerHTML = prettyBytes(torrent.length)

    // Remaining time
    var remaining
    if (torrent.done) {
      remaining = 'Done.'
    } else {
      remaining = moment.duration(torrent.timeRemaining / 1000, 'seconds').humanize()
      remaining = remaining[0].toUpperCase() + remaining.substring(1) + ' remaining.'
    }
    $remaining.innerHTML = remaining
    
    // Speed rates
    $downloadSpeed.innerHTML = prettyBytes(torrent.downloadSpeed) + '/s'
    $uploadSpeed.innerHTML = prettyBytes(torrent.uploadSpeed) + '/s'
  }
  function onDone () {
    $body.className += ' is-seed'
    onProgress()
  }
})

// Human readable bytes util
function prettyBytes(num) {
	var exponent, unit, neg = num < 0, units = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
	if (neg) num = -num
	if (num < 1) return (neg ? '-' : '') + num + ' B'
	exponent = Math.min(Math.floor(Math.log(num) / Math.log(1000)), units.length - 1)
	num = Number((num / Math.pow(1000, exponent)).toFixed(2))
	unit = units[exponent]
	return (neg ? '-' : '') + num + ' ' + unit
}
              
            
!
999px

Console