3

I'm using Pace.js (http://github.hubspot.com/pace/) for a basic loader.

It works great with no issues so far. However, what I would like to do, is append the Pace.js HTML to be inside an element of my choice.

The generated HTML looks like:

<div class="pace  pace-inactive">
    <div class="pace-progress" data-progress-text="100%" data-progress="99" style="transform: translate3d(100%, 0px, 0px);">
        <div class="pace-progress-inner"></div>
    </div>
    <div class="pace-activity"></div>
</div>

By default, Pace.js appends itself to be just after the opening <body> tag. Is there any way to hook into where this generated HTML goes?

Michael Giovanni Pumo
  • 14,338
  • 18
  • 91
  • 140

4 Answers4

5

Okay, so I figured this out. It seems to be undocumented.

In the plugins options object, there is a value for the target key.

Default options look like:

defaultOptions = {
    catchupTime: 500,
    initialRate: .03,
    minTime: 500,
    ghostTime: 500,
    maxProgressPerFrame: 10,
    easeFactor: 1.25,
    startOnPageLoad: true,
    restartOnPushState: true,
    restartOnRequestAfter: 500,
    target: 'body',
    elements: {
      checkInterval: 100,
      selectors: ['body']
    },
    eventLag: {
      minSamples: 10,
      sampleCount: 3,
      lagThreshold: 3
    },
    ajax: {
      trackMethods: ['GET'],
      trackWebSockets: true,
      ignoreURLs: []
    }
  };

In my project, I am using Browserify, so here's how I achieved this:

var pace = require('../plugins/pace');
pace.options.target = '#main';
pace.start();

This effectively overwrites the target key in the default options used by Pace.js.

Seems to work fine now. Hope this helps someone else out there.

Michael Giovanni Pumo
  • 14,338
  • 18
  • 91
  • 140
1

Okay, so I figured this out. It seems to be undocumented. In the plugins options object, there is a value for the target key.

I know it's an old thread, but I want to expand Michael's answer above mine, I managed to use Pace.js more effectively by settings:

pace.options.target = 'body:not(.pace-ignore)';

This way I can choose the elements I don't want monitored by pace (such as ads).

Tomer Gal
  • 933
  • 12
  • 21
0

Because most of pace.js's CSS makes it's position fixed, it won't be of much help only to append it to a specific element.

This is the solution to have it fill an element:

In your index.html:

<nav style="background-color: transparent; height: 5px; position: sticky; top: 0; z-index:10" id="pace-nav"></nav>
<script src="~/lib/PACE/pace.js" data-pace-options='{ "target": "#pace-nav" }'>

And in your less file:

// main: ../main.less
@import (less) "../../../node_modules/pace-progress/themes/blue/pace-theme-minimal.css";

.pace .pace-progress {
  background: #2299dd;
  position: relative;
  z-index: 2000;
  right: 100%;
  width: 100%;
  height: 5px;
}
Tudor Morar
  • 3,720
  • 2
  • 27
  • 25
-2

open css file of pace and you can change it's position by changing top : 7% !important

.pace .pace-progress {
  background: #29d;
  position: fixed;
  z-index: 2000;
  top: 7% !important;
  right: 100%;
  width: 100%;
  height: 2px;
}
Mohsin Shoukat
  • 1,190
  • 1
  • 13
  • 22