The contents table remains fixed in the top right corner as you scroll

I have developed an Angular app with a table-of-contents component that only displays two items.

The code for the script is as follows:

ts

import { Component, OnInit } from '@angular/core';
import { pdfDefaultOptions } from 'ngx-extended-pdf-viewer';

@Component({
  selector: 'app-table-of-contents',
  templateUrl: './table-of-contents.component.html',
  styleUrls: ['./table-of-contents.component.css']
})
export class TableOfContentsComponent implements OnInit {

  AOK_pdf_viewer_source: string = "/assets/AOK_T2DM.pdf";

  constructor() { pdfDefaultOptions.assetsFolder = 'assets'; }

  ngOnInit(): void { }
}

html

<div class="tableOfContentContainer">
  <div class="tableOfContent docs-toc-container">
    <div class="docs-toc-heading">Table of Contents</div>
    <nav>
      <a
        href="../assets/AOK_T2DM.pdf"
        class="docs-level-h3 docs-link ng-star-inserted"
        >Download AOK Brochure</a
      >
      <br />
      <a
        href="https://scholar.google.at/scholar?as_ylo=2021&q=diabetes&hl=en&as_sdt=0,5&as_vis=1"
        class="docs-level-h3 docs-link ng-star-inserted"
        >2021 Articles on Diabetes</a
      >
    </nav>
  </div>
</div>

<div class="container">
  <ngx-extended-pdf-viewer
    [src]="AOK_pdf_viewer_source"
    [height]="'100%'"
    width="100%"
    [useBrowserLocale]="true"
    backgroundColor="#000000"
    [textLayer]="true"
    [showHandToolButton]="true"
    zoom="page-width"
  >
  </ngx-extended-pdf-viewer>
</div>

css

.tableOfContentContainer {
    right: 100px;
    position: fixed;
    padding-top: 1em;
}

.docs-toc-container {
    border-left: 4px solid #3f51b5;
    font-weight: 700;
}

a {
    text-decoration: none;
    color: #737373;
    font-size: 16px;
    font-weight: 400 !important;
}

a:hover {
    color: #3f51b5;
}

.tableOfContent {
    padding: 5px 0 10px 10px;
    font-size: 23px;
}

The current behavior of my table-of-contents is to remain fixed while scrolling down. However, I want it to stick to the top right corner of the page and be in view at all times as the user scrolls up and down. How can I modify my code to achieve this?

In attempting to make this modification, I referenced the code on this page, but I am struggling to implement it in my own code. Can someone guide me through how to create a similar TableOfContent like the one on the tutorial page in a simple manner?

Answer №1

Prefer using the CSS property position: sticky over position: fixed:

.tableOfContentContainer {
  position: sticky;
  padding-left: 100px;
  top: 1em;
  z-index: 9999;
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Remap Objects Function with Correct Return Data Type

After receiving data from another source via a post request in a large object, I need to extract specific fields and organize them into more precise objects with some fields remapped before inserting them into a database. Currently, I have a working solut ...

What is the best way to distinguish between administrators and regular users in an Angular project?

I am embarking on a project using Angular and I plan to incorporate both an admin and a user section within it. Is there a way to effectively separate the admin area from the user area in Angular? Additionally, how can I differentiate the style files for ...

Exploring Typescript: Combining types (rather than intersecting them)

Let's analyze the scenario below type MergeFn = <K1 extends string, V1, K2 extends string, V2>( k1: K1, v1: V1, k2: K2, v2: V2 ) => ??? let mergeFn: MergeFn // actual implementation doesn't matter for this question What should b ...

Custom Component in React Bootstrap with Overflowing Column

I am working on a custom toggle dropdown feature in my React application: import React from 'react'; import 'react-datepicker/dist/react-datepicker.css'; const DateRange = props => ( <div className="dropdown artesianDropdo ...

What could be the reason for the Angular2 Component property not appearing on my webpage?

Here is the code snippet I am working with: import {Component} from "@angular/core"; @Component({ selector: 'my-app', template: ` <h1>{{title}}</h1> <h2>{{secondTitle}}</h2> <main-page></ma ...

Steps for adjusting the length in the getRangeLabel function of mat paginator

@Injectable() export class MyCustomPaginatorIntl extends MatPaginatorIntl { public getRangeLabel = (page: number, pageSize: number, length: number): string => { if (length === 0 || pageSize === 0) { return `${ ...

I'm encountering difficulty accessing the Index value within the template's Ref

I'm having trouble accessing the index value inside the templateRef. It shows as undefined in the console. <ng-container *ngFor="let notification of notifications; let i = index"> <ng-template *ngTemplateOutlet="notificationPage ...

unable to adjust the maximum height limit

I've been struggling to set a maximum height on the slider I'm currently using. No matter what height value I input, it doesn't seem to take effect. Additionally, I attempted setting the width for the echo img row in the PHP section but enco ...

Even after dynamically removing the class from the element, the Click event can still be detected

My buttons have a design like this: <a class="h-modal-btn branch-modal-btn"> Buy Now </a> The issue arises when I need to remove certain classes and add attributes to these buttons based on the query string in the URL. Skipping ahead ...

Automatically update the div every few seconds and pause when it has loaded successfully

I am facing a challenge in creating a div that refreshes automatically every 10 seconds, but stops when it successfully loads. Here is the jQuery script I have developed: <script type="text/javascript"> $(document).ready(function(){ var j = jQuer ...

The content inside the bootstrap modal is not visible

My goal is to trigger a modal window when a specific div is clicked using bootstrap modal. However, upon clicking the div, the screen darkens but the modal body fails to appear. Code: <html> <head> <title></title> ...

How can I retrieve information from an HTML or JavaScript object?

Imagine a scenario where you have an HTML table consisting of 5,000 rows and 50 columns, all generated from a JavaScript object. Now, suppose you want to send 50 checked rows (checkbox) from the client to the server using HTTP in JSON format. The question ...

Exploring the Use of throwError in Angular 7 with RxJs 6.x

I'm having trouble using the second parameter (error) in my subscriber, it doesn't seem to be working properly. Here is the code for my Observable: return Observable.create(obs => { cognitoidentityserviceprovider.adminCreateUser(params, fu ...

Keeping the Bootstrap popover anchored to the content

I have a functional bootstrap popover that includes a time attribute. However, I am looking to enhance its functionality so that it remains open when the mouse is on the content and closes only when the mouse leaves the content. Here is the relevant code ...

What is the best way to create a cornered button using CSS?

Is there a way to create a button using only CSS? https://i.stack.imgur.com/7mjVV.png This is the code I've come up with so far: .customButton { width: 100px; height: 100px; background: #6d1a3e; position: relative; transform: rotate(-90 ...

Is there a way to include text beneath the navigation bar and other elements on the page?

I am stuck trying to add some text below my header and navigation bar. Here is the code I've been working with: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta htt ...

What is the process for specifying a specific font family in CSS?

Despite setting my text to font-family: Times New Roman, I'm seeing a different font in my Chrome browser. Here is the relevant HTML code: <p style="color:#F17141;font-size: 120px; font-family: &quot;Times New Roman&quot; ; font-weight: b ...

In the iOS app when the Ionic HTML5 select keypad is opened, a bug causes the view to scroll upwards and create empty space after tapping the tab

I am currently working with Ionic v1 and AngularJS, utilizing ion tabs: <ion-tabs class="tabs-icon-top tabs-color-active-positive"> <!-- Home Tab --> <ion-tab icon-off="ion-home" icon-on="ion-home" href="#/tab/home"> <ion-nav ...

Writing CSS rules for generating HTML code when sending emails through the command line in Go

When trying to compose HTML with CSS for email delivery using Go command line execution, errors related to CSS properties are popping up. For instance, it's showing "not found" error in the terminal for properties like background: rgb(255, 255, 255) o ...

What is the best way to achieve a seamless CSS transition for my sticky navigation bar?

Looking to create a sticky bar with a smooth CSS transition instead of the current rough effect. Any tips or hints would be greatly appreciated! For reference, I found the exact animation I'm aiming for on this website: https://css-tricks.com/ Here i ...