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

Reveal the hidden div by sliding it up from the bottom

I have a container with brown branches resembling the image, and I'm looking to hide it. When a button is clicked, I want it to reveal from the bottom to the top, almost like it's being unmasked. I've ruled out a typical bottom-up slide anim ...

What could be causing the ERROR TypeError in an Angular form where "_co.service.formData" is undefined?

My attempt to create a form in Angular 7 has resulted in an error message: ERROR TypeError: "_co.service.formData is undefined" Here is the HTML code for the component: <form (sumbit)="signUp(form)" autocomplete="off" #form="ngForm"> <div clas ...

CSS is not referred to as animation

Every time we hit a key, the dinosaur receives a jump class that should activate an animation. Unfortunately, the animation does not play. animation not functioning <!DOCTYPE html> <html lang="en"> <head> <meta c ...

Inheriting Django templates for a unique CSS class markup approach

I want to create a master.html file for inheritance, but I'm facing an issue where the code is repetitive in three different places except for the body class. Here's my current master.html: <html> <head>...</head> <body& ...

Typescript ensures that the return type of a function is a key of an interface, which is determined based

I am attempting to enforce a specific return type from a function based on the key passed to it. For example, if the key is service1, then the correct return type should be Payloads['service1']. How can I accomplish this? interface Payloads { ...

Discover the steps to download web page data using Objective-C while ensuring that JavaScript has finished executing

I attempted something similar: NSString *url = @"http://www.example.com"; NSURL *urlRequest = [NSURL URLWithString:url]; NSError *error = nil; NSString *htmlContent = [NSString stringWithContentsOfURL:urlrequest encoding:NSUTF8StringEncoding error:&e ...

Node_modules seem to be missing

After completing the TypeScript 101 QuickStart tutorial using Visual Studio 2015 and Node Tools for Visual Studio, I attempted to import the 'winston' npm module. However, no matter what path I specify, Visual Studio indicates that it cannot loca ...

Enhancing the design of a button with whitespace using CSS

Recently, I had a well-designed landing page created using LeadPages. However, due to financial constraints, I am unable to continue paying for their services at the moment. The current landing page has proven to be effective in converting leads. https:// ...

No Angular applications are currently functioning in any web browsers

https://i.stack.imgur.com/uZph5.pngOne of my Angular applications is having trouble running in the browser when I use the ng serve command. Each time I try, I receive the following message in the browser: This site can’t be reached. localhost took too ...

Is there a way to ensure that the div is displayed on the same line?

Check out the jsfiddle link provided: http://jsfiddle.net/HE7yT/ I'm trying to align the Image, content, and Amount in the same line. How can I achieve this? The goal is to have "150" displayed on the same line as the picture. var HTML = $(' ...

What could be preventing the onclick event from functioning properly in JavaScript?

After creating a basic JavaScript code to practice Event handling, I encountered an issue where the function hello() does not execute when clicking on the "Click" button. What could be causing this problem? html file: <!DOCTYPE html> <html> ...

How can I add navigation dots to my slider?

I've been experimenting with my slider and I managed to make it slide automatically. However, the issue is that there is no option to manually navigate through the slides. I am looking to add navigation dots at the bottom so users can easily switch be ...

"Is it possible to differentiate between a variable that is BehaviorSubject and one that is not

I am dealing with a variable that can be of type Date or BehaviorSubject<Date | null>. My concern is figuring out how to determine whether the variable is a BehaviorSubject or not. Can you help me with this? ...

Set the dropdown item as selected using AngularJS

I have created a demo of an AngularJS dropdown menu, and it's working perfectly. Now, I want to make the selected item appear active. I'm not sure how to achieve this. Can anyone please assist me? I am using the Angular-Dropdown.js library. Here ...

Master the art of iterating through an Object in TypeScript

I need help with looping through an Object in TypeScript. While the following examples work in JavaScript, I understand why they pose a problem in TypeScript. Unfortunately, I am struggling to find the correct approach to solve this issue. Am I approaching ...

Tips for simulating a Ref

I have a Vue3 component where, within the setup(), I have defined the following function: const writeNote(note: Ref<Note>) => { console.log(`note ${note.id}`) } This function takes a Ref<Note>, with Note being an Interface. There are two s ...

What enables typescript to be eligible for transpiling is its equivalent level of abstraction to javascript?

Transpilation is the act of converting code from one language to another with a similar level of abstraction. Can you point out some distinctive characteristics that indicate TypeScript transpires into JavaScript? ...

Tips for maintaining a stationary element with fluctuating height positioned at the bottom in React

I am trying to create a fixed element with dynamic height, meaning its size changes when the browser window is resized. You can see an example of what I'm talking about here: https://stackblitz.com/edit/react-yuqarh?file=demo.tsx This element acts li ...

What is the reason for making the position of bg-container absolute?

Discover more about the "position: absolute" attribute Remove the position property for troubleshooting After testing this page in Chrome, I encountered a confusion regarding the usage of the position property within the bg-container. To my surprise, del ...

Utilize Bootstrap columns to maximize vertical space efficiency

I recently came across a bootstrap layout like this: In this setup, there is a single .row that contains 8 .col-lg-3 divs. However, I noticed that there is excessive vertical whitespace present, which not only looks undesirable but also makes the layout a ...