What is the best way to remove a scrolling event handler from a particular element or class in JavaScript?

My goal is to set up a Table of Contents (TOC) in Obsidian that remains visible as you scroll through the page. Everything functions properly until you reach about halfway down the page, at which point the TOC mysteriously vanishes.

#TOC,
.TOC {
  position: fixed;
  top: 2rem;
  right: 0;
  display: inline-block;
  float: right;
  z-index: 10;
}
<div id="TOC">
  <ul>
    <li><a class="internal-link" data-href="#Explore" href="#Explore" target="_blank" rel="noopener">Explore</a></li>
    <li><a class="internal-link" data-href="#New" href="#New" target="_blank" rel="noopener">New</a></li>
  </ul>
</div>

I've attempted using both classes and IDs for the TOC. It seems that there is a scrolling event associated with the main class that causes other elements to disappear from view as you scroll past them.

Due to my lack of knowledge in Javascript, I have resorted to adding images with text to troubleshoot. Upon inspecting the element, I discovered the following:

Once I scroll past the midpoint of the page, the TOC disappears completely.

All I want is for the TOC to remain fixed in the corner. How can I eliminate the scrolling event affecting the TOC? Removing the scrolling event entirely resolves the issue, but it resets upon app restart or refresh.

Is there a way to assign a specific class/div/ID to the TOC and disable the scrolling event for that particular element? If not, how can I remove the scrolling event altogether?

I anticipated the TOC to maintain a fixed position in the corner (sticky positioning did not work). The problem arises when the scrolling event handler dynamically hides divs and classes that are out of view.

Answer №1

If you're up for a challenge, give this a try. It may seem tricky at first, but perhaps with some clever JavaScript you can make it work.

When using Obsidian, you might notice that only a portion of the page is displayed at any given time. I encountered this issue when trying to add numbered captions to images and videos. As you scrolled down the page, the numbering would reset from the beginning if there were more than just a few items.

Below is the code snippet I crafted to address this problem:

.workspace-leaf-content {
    counter-reset: figures;
    counter-reset: videos;
}

.internal-embed.image-embed.is-loaded {
    counter-increment: figures;
}

.internal-embed.media-embed.is-loaded {
    counter-increment: videos;
}

.image-embed::after {
    display: block;
    font-variant: small-caps;
    font-weight: bold;
    font-size: 90%;
    content: 'Fig. ' counter(figures) '. ' attr(alt);
}

.media-embed::after {
    display: block;
    font-variant: small-caps;
    font-weight: bold;
    font-size: 90%;
    content: 'Vid. ' counter(videos) '. ' attr(alt);
}

.internal-embed+.footnote-ref,
.media-embed+.footnote-ref {
    display: inline-block;
    vertical-align: bottom;
}

.image-embed,
.media-embed {
    margin-left: initial;
}

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

Scrapy-splash seems to be encountering difficulties in extracting elements during the scraping process

My attempt to extract data from this Why is Splash not working here? Does anyone have a solution for me? Your assistance will be highly appreciated! ...

Design a CreateJS/EaselJS website, comprised of multiple web pages, that is not focused on gaming

I have developed an existing HTML5 Canvas webpage composed of multiple pages, buttons, and hotspots using pure canvas javascript code. The reason I refer to 'buttons' and 'hotspots' in quotes is because I created them from scratch in j ...

VueJS avoids displaying a specific data in every iteration of a v-for loop

Presented below is the code that I have managed to successfully get working: <span v-for="(item, index) in storedUserItems"> <template v-if="item.strength"> <img @mouseover="itemInfo(item, index)" style="padding: 5px;b ...

Displaying various results using a range slider

I really need some assistance in making this range slider produce multiple outputs. I've attempted a few different options, but unfortunately, I haven't been able to figure it out. My goal is to have the text "590" display as 5.9 times the value ...

Utilizing Multiple Checkboxes for Precision Search Refinement

Big thanks to Khalid Ali for the support provided up until now. I am currently working with an array of songs that each have descriptions, keywords, etc. I have a set of checkboxes that I want to use to refine a search. Essentially, if someone selects the ...

Using a sequence of array methods like filter, map, and reduce in succession instead of relying on a double loop

Having encountered a perplexing issue that I can't seem to comprehend... here is what I am attempting to achieve. Presented with the following array of objects, products = [ { name: 'Sonoma', ingredients: ['artichoke', 's ...

What are the steps to make a counter-clockwise dial with jQuery Knob?

Is there a way to use multiple instances of jQuery.countdown? Can I create countdown circles using jQuery Knob? Find examples here and here. Using Multiple instances of jQuery.countdown <div data-countdown="2016/01/01"></div> <div data-co ...

Create a new JavaScript object by parsing JSON data

I am looking to achieve the following: var my_data = { x : 'orange', y : 2 } function object(data){ this.x = 'banana'; this.y = 3; this.z = 'default value'; } once I have executed: var new_instance = ob ...

VueJS not refreshing DOM after AJAX data modification

Utilizing Vue.js to make changes to my DOM, I have implemented the fetch_data() method. This method attempts to update data.messages to display 'Love the Vue.JS' once the AJAX call is successfully completed. The AJAX call executes successfully a ...

Creating a paginated table with Nextjs, Prisma, and SWR: A step-by-step guide

I am attempting to set up a paginated table utilizing Nextjs, Prisma, and SWR. The table will display a list of invoices sorted by their ID. Here is an example of what it would look like: https://i.sstatic.net/WymoH.png To fetch all the data to the api r ...

Pass the initial value from a parent component to a child component in ReactJS without the need for state management

Initially, I have a parent Component A that calculates an initial value for its child Component B. The initial value is computed in the componentDidMount() of Component A and passed to B using props: <ComponentB initialValue={this.state.value} handleCha ...

CSS or Coding? Learn how to display items side by side instead of on top of each other

Hey there! I manage a music website that is currently in beta. I'm running into an issue with the way the music results are appearing in the bottom player - they're all stacked on top of each other instead of being listed side by side. I've ...

Leveraging x-template in VueJS to create a sub-component within a larger component

I'm having trouble understanding how to properly use x-template for a subcomponent within a VueJS component. My component, CategoryNav.vue, has a template that uses an x-template to display a list. However, when I render the page, the component creat ...

An easy way to adjust the date format when linking a date in ng-model with md-datepicker

<md-input-container> <label>Scheduled Date</label> <md-datepicker ng-model="editVersionCtrl.selectedPlannedDate" ng-change="editVersionCtrl.checkPlannedDate()"> </md-datepicker> </md-input-container> ...

How can I invoke object functions stored in an array using Javascript?

I'm currently attempting to iterate through an array of game objects and invoke their update methods. The challenge is that game objects may have different update implementations - for example, the update function for an enemy is different from that o ...

The error message "TypeError XXX is not a function in NodeJS" indicates that

As I attempt to enhance the testability of my NodeJS API by incorporating a service, a peculiar issue arises. Specifically, upon injecting the service (class), an error is triggered stating that the method getTasks() does not exist. ROUTE const TodoServi ...

The getList() function from Restangular is failing to return the expected JSON data

I'm facing an issue with retrieving data from a Restangular promise. Instead of receiving pure JSON data, I always end up with a promise object. Here is the response from my API: localhost:3000/api/meal { "status": "success", "data": [ { ...

Guide to aligning a URL in an HTML file

Greetings all, I'm new to HTML and struggling with how to center a URL on my webpage. For example: <a href="http://www.google.com"> Click Here to Open Google </a> I attempted using the tag and the STYLE attribute but without success. ...

angular-in-memory-web-api encounters a 404 error

I recently completed the heroes tour and now I am trying to work on something similar, but I seem to be having trouble understanding angular-in-memory-web-api. Here is a snippet of my code: clients-data.service.ts import { Injectable } from '@angular/ ...

What could be the reason my website is not saving the user input information to the database?

Hello! I am a novice programmer attempting to create a basic registration function on my website. I have set up a simple form for users to input their information, but I am facing an issue where the user data is not being stored in my database. ...