Use two different Pace.js progress bars on the same page

by Yi Zeng

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/pace/1.0.2/pace.min.js"></script>
<body class="content-loading">
    <button onclick="Pace.restart()">Trigger Ajax</button>
    <button onclick="location.reload()">Reload Page</button>
</body>

CSS

.content-loading>:not(.pace),
.content-loading:before,
.content-loading:after {
    -webkit-transition: opacity .4s ease-in-out;
    -moz-transition: opacity .4s ease-in-out;
    -o-transition: opacity .4s ease-in-out;
    -ms-transition: opacity .4s ease-in-out;
    transition: opacity .4s ease-in-out
}

.content-loading:not(.pace-done)>:not(.pace),
.content-loading:not(.pace-done):before,
.content-loading:not(.pace-done):after {
    opacity: 0
}

.content-loading .pace.pace-inactive {
    display: none;
}

.content-loading .pace {
    -webkit-pointer-events: none;
    pointer-events: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    user-select: none;
    z-index: 2000;
    position: fixed;
    height: 60px;
    width: 100px;
    margin: auto;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}

.content-loading .pace .pace-progress {
    z-index: 2000;
    position: absolute;
    height: 60px;
    width: 100px;
    -webkit-transform: translate3d(0, 0, 0) !important;
    -ms-transform: translate3d(0, 0, 0) !important;
    transform: translate3d(0, 0, 0) !important;
}

.content-loading .pace .pace-progress:before {
    content: attr(data-progress-text);
    text-align: center;
    color: #fff;
    background: #29d;
    border-radius: 50%;
    font-family: "Helvetica Neue", sans-serif;
    font-size: 14px;
    font-weight: 100;
    line-height: 1;
    padding: 20% 0 7px;
    width: 50%;
    height: 40%;
    margin: 10px 0 0 30px;
    display: block;
    z-index: 999;
    position: absolute;
}

.content-loading .pace .pace-activity {
    font-size: 15px;
    line-height: 1;
    z-index: 2000;
    position: absolute;
    height: 60px;
    width: 100px;
    display: block;
    -webkit-animation: pace-theme-center-atom-spin 2s linear infinite;
    -moz-animation: pace-theme-center-atom-spin 2s linear infinite;
    -o-animation: pace-theme-center-atom-spin 2s linear infinite;
    animation: pace-theme-center-atom-spin 2s linear...

JavaScript

Pace.on('hide', function() {
    document.getElementsByTagName("body")[0].classList.remove('content-loading');
    document.getElementsByTagName("body")[0].classList.add('content-loaded');
});