StringTune/Docs

Modules

StringParallax

Transforms scroll progress into parallax travel and emits a numeric object event.

Type
Built-in module
Status
Stable
Scope
Element-level
Activation
string="parallax"

StringParallax

StringParallax uses the same internal timeline math as StringProgress, but its public output is different. Instead of publishing a progress variable, it computes a vertical translation and writes it directly to transform.

Public API

Attributes

AttributeTypeDefaultReal runtime effect
string-parallaxnumber0.2Sets movement strength. The runtime stores the absolute value as strength and keeps the sign as direction.
string-parallax-biasnumber0.0Redistributes movement before and after the midpoint of the travel.
string-enter-elstringtopShared timeline start geometry inherited from StringProgress.
string-enter-vpstringbottomShared timeline start geometry inherited from StringProgress.
string-exit-elstringbottomShared timeline end geometry inherited from StringProgress.
string-exit-vpstringtopShared timeline end geometry inherited from StringProgress.

CSS Variables and DOM Output

The module writes:

  • inline transform: translate3d(0, <value>px, 0)

It also emits the current translation as a number.

The current runtime does not publish a parallax CSS variable, and it does not publish object:progress:<id> for parallax elements.

Events

ChannelPayloadFired when
object:parallax:<id>numberThe current parallax translation is recomputed
TypeScript
stringTune.on('object:parallax:hero-layer', (offset) => {
  console.log(offset);
});

Mirror Behavior

If a mirror is linked with string-copy-from, the same transform string is applied to the mirror element too.

Quick Example

HTML
<section class="hero">Scroll down</section>

<section class="parallax-frame">
  <div string="parallax" string-id="hero-layer" string-parallax="0.3" class="parallax-layer">
    <div class="parallax-inner"></div>
  </div>

  <div class="parallax-center">
    <div class="parallax-label">Offset <span id="parallax-value">0</span>px</div>
  </div>
</section>

<section class="hero">Scroll up</section>
CSS
.hero,
.parallax-frame {
  min-height: 100vh;
}

.hero {
  display: grid;
  place-items: center;
}

.parallax-frame {
  position: relative;
  overflow: hidden;
  border-top: 1px solid black;
  border-bottom: 1px solid black;
}

.parallax-layer {
  position: absolute;
  inset: -25% 0;
}

.parallax-inner {
  position: absolute;
  inset: 0;
  border-top: 1px solid black;
  border-bottom: 1px solid black;
  background: repeating-linear-gradient(
    180deg,
    white 0,
    white 18px,
    black 18px,
    black 19px
  );
}

.parallax-center {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: grid;
  place-items: center;
}

Wrap the moving layer if you need any additional transform of your own. StringParallax owns the element's transform property.

Registration

TypeScript
import StringTune, { StringParallax } from '@fiddle-digital/string-tune';

const stringTune = StringTune.getInstance();
stringTune.use(StringParallax);
stringTune.start(60);

You do not need to register StringProgress separately. StringParallax already extends it internally.

Detailed Behavior

  • StringParallax computes progress internally, but it does not expose that progress as public CSS or public progress events.
  • During initialization, the module overwrites offset-top and offset-bottom with abs(string-parallax) * viewportHeight. In the current runtime, manual parallax offsets are therefore not a reliable public control surface.
  • On viewports <= 1024px, the runtime switches to a mobile branch that emits 0 and writes translate3d(0, 0px, 0).