Javascript to represent progress along irregular path


The goal is to simulate a motion by filling this path drawn over a background image using JavaScript only.
Will consider a simple way, cut in solid color, with transparent background. In real situation will be, say, a meaningful path with respect to some landscape.

In the image below to create a move in the first section of the path will use a second smaller image – the yellow block – of such shape so that one edge is as much as possible perpendicular to the path. This image will move in the background (smaller z-index) of the main image creating the desired fill effect.

        <img src="block1.png" />
        <img alt="" src="bkg.png" />

First some variables that will allow us to initially position the small image and to control a timer:

  var nTick = 100; // miliseconds
  var nStartY = 106.7;
  var timer;
  var dblStep;
  var nPosition = 0;
  var nTarget;
  // img for section 1
  var block1;
  var nBlock1X = 49;
  var nBlock1Y = 86;

The timer will repeat the function call until the path is filled or the target is reached. This example covers only the first section of the path, the rest being pretty much similar.

  function window_onload() {
    nTarget = document.getElementById("Target").value; ;
    dblStep = .5; //target / 40;
    // init
    block1 = document.getElementById("imgblock1"); = nBlock1X + "%"; = nBlock1Y + "%";
    // start timer
    timer = window.setInterval(time, nTick);
    return true;
  function time() {
    if (nPosition <= 33)
    else if (nPosition > 33)  && nPosition <= 67)
   nPosition = RoundNumber(nPosition + dblStep, 2);
   if (nPosition > nTarget)

Since the path is irregular, some adjustments to the moving image block will be needed to create a perpendicular fill. To avoid flickering the image block is hidden and displayed again after the new position is determined.

  function ShowPosition1() {
    var nClimb1RightTrans; = "none";
    if ( < 492 && > 475) {
      timer = window.setInterval(time, nTick * 2);
      nClimb1RightTrans = .8;
    else {
      timer = window.setInterval(time, nTick);
      nClimb1RightTrans = .2;
      } = (parseFloat( + nClimb1RightTrans) + "%"; = (((nStartY + ((nPosition / 33) * (nBlock1Y  - nStartY)))) - 30) + "%"; = "block";

A fine tuning situation will be to handle the small portion where the path changes direction. For this will alter two parameters of the moving: the speed and right shifting.
We can use constant values for the pixelTop since it’s all relative to the background image.

Finally, there’s another very important peculiarity of what does Cialis that brings it so high above its alternatives. It is the only med that is available in two versions – one intended for use on as-needed basis and one intended for daily use. As you might know, Viagra and Levitra only come in the latter of these two forms and should be consumed shortly before expected sexual activity to ensure best effect. Daily Cialis, in its turn, contains low doses of Tadalafil, which allows to build its concentration up in your system gradually over time and maintain it on acceptable levels, which, consequently, makes it possible for you to enjoy sex at any moment without having to time it.

By continuing to use the site, you agree to the use of cookies. More information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.