I wish for the content with "position: fixed" to stay in place without moving when it encounters this particular class while scrolling

How can I make the content with "position: fixed" stop at the designated "LimitPoint" and not continue scrolling past it?

The fixed content currently goes beyond the "LimitPoint" and disappears when scrolling to the bottom.

Is there a way to achieve the behavior shown in the attached image, where the fixed position stops at the LimitPoint?

View image reference here

If the scroll reaches the "LimitPoint" and then moves up again, I want the fixed content to follow along.

Why does the fixed content not stop at the designated "LimitPoint"?

A bit of assistance would be greatly appreciated!

+) While "position: sticky" is very convenient, this particular homepage only supports static, relative, absolute, fixed, and inherit positions. As such, I need to try implementing it with a script.

Note: I utilized a translator as English is not my native language, so please excuse any awkward phrasing in my message.

$(window).scroll(function() {
    if (window.pageYOffset > ($('.LimitPoint').offset().top - $('.fixedList').outerHeight())) {
        $('.fixedBox').removeClass('fixed');
        $('.fixedBox').addClass('Limit');
    } else {
        $('.fixedBox').removeClass('Limit');
        $('.fixedBox').addClass('fixed');
    }
});
ul,li { 
    margin: 0;
    padding: 0;
    list-style: none; }

#topArea {
    min-height: 200vh;
    background: #f4f4f4;
}

.fixedBox {
    position: fixed;
    width: 100%;
    padding: 30px;
    left: 0;
    bottom: 0; 
    border: 0;
    z-index: 88;
}

.fixedBox.fixed {
    position: fixed;
    width: 100%;
    left: 0;
    bottom: 0; 
    z-index: 88;
}

.fixedBox.Limit {
    position: absolute; 
    left: 0;
    bottom: 0; 
    z-index: 88;
}

.fixedBox .fixedList { 
    color: coral;
    font-size: 30px;
    font-weight: 600;
}

.LimitPoint {
    width: 100%;
    height: 1px;
    background: red;
}

#bottomArea {
    position: relative;
    margin: 120px 0 0;
    padding: 0 5%;
}

#bottomArea ul div {
    position: relative;
    display: flex;
    flex-direction: row;
}

#bottomArea ul li {
    padding: 7px;
}

#bottomArea ul li img {
    width: 100%;
    height: auto;
}
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>

<div class="fixedBox">
    <ul class="fixedList">
        <li>content</li>
        <li>content</li>
        <li>content</li>
        <li>content</li>
    </ul>
</div>

<div id="topArea"> </div>


<div class="LimitPoint"></div>


<div id="bottomArea">
    <ul>
        <div>
            <li><img src="https://url.kr/inj9yz"></li>
            <li><img src="https://url.kr/inj9yz"></li>
            <li><img src="https://url.kr/inj9yz"></li>
        </div>
        <div>
            <li><img src="https://url.kr/inj9yz"></li>
            <li><img src="https://url.kr/inj9yz"></li>
            <li><img src="https://url.kr/inj9yz"></li>
        </div>
    </ul>
</div>

Answer №1

If you want to achieve this using only CSS without any JavaScript, you can rearrange the .fixedBox element as shown below:

ul,li { 
    margin: 0;
    padding: 0;
    list-style: none; }

#topArea {
    min-height: 200vh;
    background: #f4f4f4;
}

.fixedBox {
    position: sticky;
    width: 100%;
    padding: 30px;
    left: 0;
    bottom: 0; 
    border: 0;
    z-index: 88;
}

.fixedBox .fixedList { 
    color: coral;
    font-size: 30px;
    font-weight: 600;
}

.LimitPoint {
    width: 100%;
    height: 1px;
    background: red;
}

#bottomArea {
    position: relative;
    margin: 120px 0 0;
    padding: 0 5%;
}

#bottomArea ul div {
    position: relative;
    display: flex;
    flex-direction: row;
}

#bottomArea ul li {
    padding: 7px;
}

#bottomArea ul li img {
    width: 100%;
    height: auto;
}
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>


<div id="topArea"> </div>

<div class="fixedBox">
    <ul class="fixedList">
        <li>content</li>
        <li>content</li>
        <li>content</li>
        <li>content</li>
    </ul>
</div>

<div class="LimitPoint"></div>


<div id="bottomArea">
    <ul>
        <div>
            <li><img src="https://url.kr/inj9yz"></li>
            <li><img src="https://url.kr/inj9yz"></li>
            <li><img src="https://url.kr/inj9yz"></li>
        </div>
        <div>
            <li><img src="https://url.kr/inj9yz"></li>
            <li><img src="https://url.kr/inj9yz"></li>
            <li><img src="https://url.kr/inj9yz"></li>
        </div>
    </ul>
</div>

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

Method for setting a checkbox as checked based on whether its value can be found in an array

I currently have the following input fields: <div id="my"> <input type="checkbox" value="1" name="names[]"> <input type="checkbox" value="2" name="names[]"> <input type="checkbox" value="3" name="names[]"> <input t ...

While creating a React app, Docker becomes stuck due to a hangup when checking the core-js dependency

I've hit a roadblock in the build process. I'm working on an M1 Mac Mini and have attempted to build in both arm64 and x86_64 terminals, but the outcome is consistently the same. npm info lifecycle @babel/<a href="/cdn-cgi/l/email-protection" ...

Ways to generate a unique link for every value in an option tag dynamically?

I'm currently working on a form that allows customers to buy an online service. Within the form, there's a dropdown list featuring 'select' and 'option' tags. This dropdown menu lets users pick a billing cycle (6 months, 1 ...

Modifying the input field's name attribute while utilizing multiple datasets in typeahead.js

I am currently utilizing typeahead.js with multiple datasets, following the guidance provided here. I have chosen not to employ Bloodhound in my implementation, resulting in some differences in my code structure, outlined below: $('#search .typeahead ...

How to identify the node with the appropriate date range attribute using JavaScript or jQuery

I am seeking assistance in using Javascript, preferably jQuery, to identify the specific "node" within an XML structure where a given date falls between its "begin" and "end" dates. XML EXAMPLE: <nodes> <node begin="2014-01-01" end="2014-01- ...

Issue with dynamic creation of menu in React Material UI where onClose function is unable to reference a variable inside the function

As I develop an app, I have chosen to dynamically construct the settings menu based on a JSON file. { categories: [ { name: "General", index: 1, items: [{ name: "Dark Mode", index: 1 ...

Tips for integrating AsyncGenerators with Kotlin/JS

I am currently exploring the use of IPFS with Kotlin/JS, but my issue is not limited to that specific context. The functions ipfs.cat() and ipfs.get() return an AsyncGenerator, and I am uncertain about how to properly iterate over it using Kotlin (I am als ...

Angular is showing an error indicating that the property "name" is not found on an empty object

After thorough checking, I have confirmed that the property does exist with the correct key. However, it is returning an error message stating name is not a property of {}. I attempted to assign this object to an interface along with its properties but enc ...

What is the best way to update React State after making an asynchronous call to MongoDB?

I have been facing a common issue, but couldn't find an up-to-date solution on Stack Overflow specifically for React/Meteor. My goal is to query a mongoDB to retrieve data and then pass it into the state of my React components. Currently, I am queryin ...

Once the timer has finished, I would like for a specific component to be displayed

I am trying to make my component CountDownSquare disappear once the timer has fully counted down. In my homePageData, I have the main text stored in a h3 element that should only appear once the countdown is complete. I attempted to use a ternary stateme ...

I attempted an AJAX script, but unfortunately, it was unsuccessful. Upon submitting the form, I received a success alert, but no data was sent to

I have been struggling with an Ajax script that doesn't seem to be working as expected. When I submit the form, I receive a success alert but nothing is being sent to the database. Here is my HTML form: <form action="account_info.php" enctype="mu ...

Tips for minimizing separation by utilizing timeline panels in Bootstrap

Is there a way to decrease the spacing between each panel? Right now, they are too far apart and when I fill up a lot of space, the navigation bar always shows up. I don't want that horizontal bar to be visible. I want to avoid that bar from appearin ...

Maintain the proportion of the browser window when reducing its size

<html> <head> <link rel="stylesheet" href="style.css" type="text/css" /> </head> <body> <img src="spacer--1200x800.png" width="1200" height="800" /> </body> </html> This section contains CSS ...

I'm not sure how I can retrieve the pollId from a ReactJS poll

In my React code, I am fetching a poll using an API. However, I am facing an issue while working on the handleChange function for making a POST API request. The information required for the request includes PollId, userId, and answer. I am able to retrieve ...

Guide to troubleshooting JavaScript in Firefox using Visual Studio 2008?

In the header section of my ASPX page, I have some scripts that I would like to debug with breakpoints in Firefox. ...

Avoid Scrolling within an iFrame in HTML with the Use of #

I have a menu loading in an iframe with links using # like http://<location>/page.html#part1. When I click inside the iframe, the entire page outside of the iframe scrolls to the location of #. How can I stop this from happening? I only want the me ...

What could be causing my Squarespace animation to function properly in Chrome but not in Safari?

I successfully implemented a typewriter animation on my Squarespace website using a Code Block and HTML code. It seems to be functioning well on Google Chrome but is not working on Safari. I recall reading that 'transform' may require additional ...

I'm currently in the process of designing unique tabs, however, the content within the tabs

My current project involves creating tabs where all the tab content is inside one div with a position:relative, and each content div has been given a position:absolute. The issue I'm facing is that when the position is set to absolute, the content ov ...

Data is not appearing when using Node.js with mongoose and the populate() method

I am facing an issue while trying to display data from a database. Even though I have integrated 3 different schemas into one, the combined data is not being displayed as expected. I have attached all three schemas for reference. While async-await along w ...

The Javascript alert is displaying twice in Internet Explorer

My file validation function is set up to only allow the uploading of xls files, and it works properly by displaying an error message if a non-Excel file is uploaded. However, there is an issue with the alert firing twice in IE. Here is my code: function ...