Home

Awesome

ngx-tracing-beam

<a href="https://ngxui.com" target="_blank" style="display: flex;gap: .5rem;align-items: center;cursor: pointer; padding: 0 0 0 0; height: fit-content;"> <img src="https://ngxui.com/assets/img/ngxui-logo.png" style="width: 64px;height: 64px;"> </a>

This Library is part of the NGXUI ecosystem. <br> View all available components at https://ngxui.com

@omnedia/ngx-tracing-beam is an Angular component that renders a dynamic tracing beam that follows the user's scroll progress. This component is ideal for visually connecting different sections of content on a page, providing an interactive and engaging user experience.

Features

Installation

Install the library using npm:

npm install @omnedia/ngx-tracing-beam

Usage

Import the NgxTracingBeamComponent in your Angular module or component:

import {NgxTracingBeamComponent} from '@omnedia/ngx-tracing-beam';

@Component({
  ...
    imports:
[
  ...
    NgxTracingBeamComponent,
],
...
})

Use the component in your template:


<om-tracing-beam
  [strokeColor]="'#3498db'"
  [gradientTop]="'#ffcc00'"
  [gradientMiddle]="'#e74c3c'"
  [gradientBottom]="'#9b59b6'"
  [animationDuration]="700"
  styleClass="custom-tracing-beam"
>
  <div class="content-section">
    <h2>Section 1</h2>
    <p>Your content here...</p>
  </div>
  <div class="content-section">
    <h2>Section 2</h2>
    <p>Your content here...</p>
  </div>
</om-tracing-beam>

How It Works

API


<om-tracing-beam
  [strokeColor]="strokeColor"
  [gradientTop]="gradientTop"
  [gradientMiddle]="gradientMiddle"
  [gradientBottom]="gradientBottom"
  [animationDuration]="animationDuration"
  [easingFunction]="easingFunction"
  styleClass="your-custom-class"
>
  <ng-content></ng-content>
</om-tracing-beam>

Example


<om-tracing-beam [strokeColor]="'#e74c3c'" [gradientTop]="'#3498db'" [gradientMiddle]="'#2ecc71'" [gradientBottom]="'#9b59b6'">
  <div class="content">
    <h2>Scroll-Linked Content</h2>
    <p>This content is linked with a dynamic tracing beam that follows the scroll progress.</p>
  </div>
</om-tracing-beam>

This example creates a tracing beam with a red stroke and a blue-to-purple gradient that animates as the user scrolls through the content.

Smart Scroll Context

When the om-tracing-beam is used in different scroll contexts, such as directly within the viewport or inside a nested scrollable element, it intelligently binds the scroll event listener to the nearest scrollable parent or defaults to the window if none is found. This ensures the beam's position is always calculated relative to the correct scroll context. <br> This example shows how you can integrate the tracing beam within a scrollable div to ensure it functions correctly across multiple environments:


<div style="height: 700px; overflow-y: scroll;">
  <om-tracing-beam styleClass="nested-scroll-context">
    <div style="height: 2000px;">
      <!-- Long content that makes the container scroll -->
      <h1>Start of Content</h1>
      <p>Content continues...</p>
    </div>
  </om-tracing-beam>
</div>

Styling


<om-tracing-beam styleClass="custom-beam-style">
  <div class="content">
    <h2>Styled Tracing Beam</h2>
    <p>Customize the beam with your own styles.</p>
  </div>
</om-tracing-beam>
/* Global styling */
.custom-beam-style .beam-dot {
  background-color: #ffcc00;
  border: 2px solid #e74c3c;
}

.custom-beam-style .beam-inner-dot {
  background-color: #2ecc71;
  border-color: #27ae60;
}

This CSS will style the dot at the start of the tracing beam with custom colors.

Contributing

Contributions are welcome. Please submit a pull request or open an issue to discuss your ideas.

License

This project is licensed under the MIT License.