Is there a way to determine if a container is overflowing at the top?

Currently, I am using Puppeteer to scrape Slack. My goal is to confirm whether I have scrolled to the very top of the channel feed.

The issue arises because the channel feed does not actually scroll, making it impossible for me to utilize the method outlined on MDN:

element.scrollHeight - Math.abs(element.scrollTop) === element.clientHeight

In a scenario where the element itself does not scroll but its child elements overflow, the suggestion is to inspect the computed style:

window.getComputedStyle(element).overflowY === 'visible'

However, this solution does not seem to work for two reasons. Firstly, in this particular case, it appears that the overflow hidden property is set on another parent container, causing the container I'm observing to always have a computed overflowY style of visible. Secondly, when I am scrolled all the way to the top, the child elements will by nature overflow downwards rather than upwards.

So, the question remains: how can I validate if a container overflows specifically at the top?

If you wish to test your code on the specific element I am examining within the Slack App, simply log into a Slack workspace and select that element using the console with:

document.querySelector(`[aria-label="${channelName} (channel)"]`)

Replace channelName with something like 'general' or the name of the active channel currently displaying its feed.

Answer №1

Finally, a solution that gets the job done! By targeting the channel feed container and examining its top edge's position in relation to the viewport, I can determine if there is more content to scroll through.

const channelFeed = document.querySelector(`[aria-label="${channelName} (channel)"]`)
const isScrolledToTop = channelFeed.getBoundingClientRect().y > 0

This method is effective because the channel feed container remains stationary without scrolling. The individual posts it contains span the full length of the page, with overflow hidden at the top and bottom. This approach allows me to check for any overflowing content beyond the viewport's top edge.

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

Creating a table with a tableHead cell comprised of multiple components in ReactJS/CSS using Material UI

It's possible that the title lacks description. I am attempting to generate a table with a specific layout like this https://i.sstatic.net/T97C2.gif Essentially, the "Average" cell is combined with two smaller cells for "height" and "width," which c ...

Manually incorporating multiple React components into a single container

I am currently in the process of upgrading an old JavaScript application that relies heavily on jQuery by introducing some React components. The existing code utilizes JS/jQuery to dynamically add elements to the DOM, and I am looking for a way to replace ...

Tips for transferring information from the isolate scope to the parent scope

As a newcomer to AngularJS, I am exploring the creation of directives and how to invoke functions from the parent scope within them. While I have successfully achieved this, I am now grappling with the challenge of passing data from the isolate scope via a ...

Button component in React remains visible until interacted with

https://i.stack.imgur.com/gTKzT.png I'm dealing with a sign out component in my app that requires me to click on it specifically to unselect any part of the application. This is implemented using React Material UI. <MenuItem onClick={e => this ...

Proper Sequence of Bootstrap Header Configuration

I'm working on creating a header/navbar using bootstrap, but I'm unsure about the correct order and method to achieve this. This is how I want it to look: And when collapsed: Should everything be contained within the NAV tag? I have a header ...

What is the most effective method for incorporating access token authentication in a React application?

As a newcomer to React, I am working on implementing authentication using Express.js in my react web application. I have successfully set the token in response cookies on the backend with the HttpOnly flag, but unfortunately, I am unable to read it on the ...

Determining if a date has passed using moment.js, focusing solely on the date

Is it possible to determine if a date has passed based solely on the date itself? Currently, I am using !moment(moment().format("LLL")).isBefore(moment.unix(data.dueDate._seconds).format("LLL")). However, this approach also takes into account the time. F ...

transforming an array into JSON structure using node.js

Hello, I have a list of data that I need to convert into JSON format. Here is an example of how I want the data to look: [ { "slideName": "s0", "imageUrl": "https://s3.amazonaws.com/lifestyle345/testing/slides/cbaa5e650152a0332b494f0074985 ...

Determine the week number based on a specified starting day for the week

If I have a custom week start day other than Monday, how should the getWeekNumber() prototype for the Date class be modified? Here is the existing code for calculating the ISO Week Number: Date.prototype.getWeekNumber = function() { // Create a dupli ...

retrieve today's date with parsed time using moment

I am attempting to retrieve the current date and time, with the specified time using moment js. Here's what I have tried. const time = '18:00' const timeAndDate = moment(time) However, when I display timeAndDate, it indicates an invalid da ...

Tips on how to round a whole number to the closest hundred using Javascript

Suppose there is a numerical value given let x = 890 and the objective is to round it off to 900. If the number is 820, then it should be rounded to 800. We can safely assume that the input number (x) will always be an integer. While manually checking ...

Utilizing JavaScript for loops to extract the final element from an array

I am facing an issue with the second loop within a function that goes through a JSON file. The problem is that it only returns the last item in the array. I need to figure out how to fix this because the chart object should be created on each iteration, ...

unable to retrieve access-token and uid from the response headers

I am attempting to extract access-token and uid from the response headers of a post request, as shown in the screenshot at this https://i.sstatic.net/8w8pV.png Here is how I am approaching this task from the service side: signup(postObj: any){ let url = e ...

Combine Vue Plugin Styles without Using Components

Question Time To clarify, when I mention 'without component', I am referring to my plugin being a custom Vue Directive that does not rely on a template. It acts as a wrapper for a class, without the need for an additional component. However, I a ...

execute action once element has finished loading - angular

I am looking for a way to trigger an angular function after a specific element has been displayed on the page. The challenge arises because this element is part of a Single Page Application (SPA) where its display is controlled by a series of events. Tradi ...

Creating a sleek and functional dashboard using HTML and leveraging the power of Bootstrap 4

I'm working on styling my HTML dashboard with Bootstrap 4. I want the text to be big and have minimal white space, but not too cluttered. <html> <head> <meta charset="utf-8"> <meta name="viewport" conte ...

Flameflare/Console-inspired hover animation

Curious if there is a creative solution to this problem that I haven't thought of yet... I'm working on a site editor tool and it would be incredibly useful to have the ability to highlight elements when hovering over their code in the html/elem ...

Adding an HTML arrow icon within a button

As I work on creating an HTML email, my aim is to incorporate a right arrow onto an HTML button. To achieve this, I have opted to utilize a special character and apply the transform-rotate property. However, I am facing an issue where the text and arrow a ...

Eliminate any height changes in the ul element during a CSS transition

Here is the code I've been using to style my side navigation, which has been working perfectly without any transitions. SCSS Code and a functional JSFiddle .side-nav{ position: fixed; z-index: 100; right: 0; margin-top: 15vh; ul { lis ...

What does [] represent in the context of the [].forEach.call() method?

I'm a bit confused about the meaning of [] in the code snippet below. Is it just indicating the most recently declared array? Can someone provide clarification? In this particular example, we have two arrays named racersList and volunteersList stored ...