The scroll feature is not functioning properly in detecting the CSS function for the final div


$(document).ready(function() {
    $(document).on("scroll", onScroll);

    //smoothscroll
    $('a[href^="#"]').on('click', function(e) {
        e.preventDefault();
        $(document).off("scroll");
        $('a').each(function() {
            $(this).removeClass('actve');
        })
        $(this).addClass('actve');

        var target = this.hash,
            menu = target;
        $target = $(target);
        $('html, body').stop().animate({
            'scrollTop': $target.offset().top + 2
        }, 500, 'swing', function() {
            window.location.hash = target;
            $(document).on("scroll", onScroll);
            var scroll_start = 0;
            var startchange = $('.q-intro-text');
            var offset = startchange.offset();

        });
    });
});

function onScroll(event) {
    var scrollPos = $(document).scrollTop();
    $('#q-nav a').each(function() {
        var currLink = $(this);
        var refElement = $(currLink.attr("href"));
        if (refElement.position().top <= scrollPos && refElement.position().top + refElement.height() > scrollPos) {
            $('#q-nav ul li a').removeClass("actve");
            currLink.addClass("actve");
            $('.actve').css('color', '#4d4d4d');
            $('.actve').css('border-bottom', '1px solid #ff363f');
        } else {
            currLink.removeClass("actve");
            currLink.css('color', '#898989');
            currLink.css('border-bottom', '1px solid white');
        }
    });
}

.container { padding: 0; width: 100vw; height: 100vh; }

.menu { display: none; }

header { display: none; }

.carousel-indicators li.active { width: 1.3rem; height: 1.3rem; margin-right: 0.8rem; }

#myTopnav { display: none; }

#myTopnav .q-hamburger { display: none; }
/* Add more CSS styles here */
<!DOCTYPE html><br>

<head>
    <meta charset="utf-8">
    <title>Sample Page</title>
    <link rel="stylesheet" href="styles.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <script src="scripts.js"></script>
</head>

<body>
    <header>
        <button class="hamburger">☰</button>
        <button class="cross">×</<ltbutton>
    </header>

    <div class="menu">
        <ul>
            <li>Menu Item 1</li>
            <li>Menu Item 2</li>
            <li>Menu Item 3</li>
        </ul>
    </div>

    <div class="content">
        <p>This is a sample webpage with dynamic scrolling effects.</p>
    </div>

    <script>
        $(document).ready(function(){
            $(".hamburger").click(function(){
                $(".menu").slideToggle("slow");
            });

            $(".cross").click(function(){
                $(".menu").slideToggle("slow");
            });
        });
    </script>
</body>

The issue you are facing with the `#contact-us` div may be due to missing or incorrect CSS classes applied to it in your code. Make sure that the necessary CSS classes are defined and correctly linked to the elements within the `#contact-us` section. Check for any errors in the CSS file or script that might be affecting the styling of this specific section.

Answer №1

When viewing your website in certain browsers, the black background of the "Contact us" section can overlap with the navbar, making the red line invisible when the last link is active.

In other browsers, the height of the "contact us" section may not allow users to scroll far enough to activate that last link. Setting the height to 100% doesn't always produce the expected results.

To resolve this issue, you can remove the black background color and increase the height slightly beyond the viewport height to ensure there is enough space for scrolling:

Answer №2

  window.addEventListener(
        'scroll',
        function( event ){      
            var $element = $( event.target );  
           if(  $element.scrollTop() + $element.innerHeight() >= $element[0].scrollHeight && element.is( "selected element" ) ) {               
                    //custom code goes here
           }  
   });

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

Determine the item in a collection of objects that contains a specific key

What is the most efficient method for locating an object by a specific key in JS when given an array of objects? Utilizing jQuery and underscoreJS is acceptable. I am simply seeking the simplest solution with minimal code. Illustration: Suppose we have a ...

Unable to manage the DatePicker error in Material UI

https://i.sstatic.net/S6yaQ.png I am facing an issue with the DatePicker component where it displays a red border when there is an empty value. Setting true/false to error attribute does not seem to have any effect. Even passing error to the TextField co ...

Enhancing Your Vue Experience: A Guide to Highlighting and Selecting HTML Elements on Mouse Hover

Incorporating a navigation header using Vue, I utilize v-html to display it seamlessly. Check out the demo - here <section class="text-gray-700 font-heading font-medium relative bg-gray-50 bg-opacity-50"> <nav class="flex justify ...

Is it possible to generate a separate table for each user using PHP?

Embarking on a new adventure, I have chosen to create an online shopping website for a college project. My roadblock comes at the sign-up stage. I envisioned users having separate tables to store products they add to their carts, allowing them to add more ...

The previous successful execution of req.body is now yielding an undefined value

My req.body is suddenly undefined, even though it was working fine a few days ago. I've tried using the deprecated body-parser module, but no luck. Here's my code: JS: var express = require("express"); var router = express(); require(& ...

When the children within a CSS container are floated, set the height of the container to

I've established a simple layout <div class="container"> <div class="sidebar"> </div> <div class="content"> </div> <div style="clear:both;"></div> </div> where .sidebar and .content ...

Transmit information using $broadcast when a button is clicked, and retrieve that information using $scope.$on

I am trying to create a function that will broadcast data from the server upon button click, and then navigate to a new route using $state.go('new-route'). In the controller of this new state, I want to retrieve the transmitted data. However, whe ...

Switch the text style when hovering, then switch it back upon second hovering

Searching for a method to modify the font of individual letters when hovering over them. The goal is for the letters to revert back to their original font after a second hover (not on the first hover-off). Any assistance would be greatly valued! ...

Utilizing the require function to implement an AngularJS Controller without having

I've been working with requireJS in my application. Every time I try to register a controller on my module, it gives me an error saying that the controller is not defined. Here's the code for my LoginController located in login.controller.js: f ...

Adding elements to an array appears to cause the previously created object to react

I am encountering a situation where once I add an object to an array, it becomes reactive to any changes made. // actions.js export const addToCart = ({ commit }) => { commit('addToCart'); // successfully updates the state setTimeout ...

In jQuery, a dropdown selection can be filled with multiple textboxes sharing the same class

I'm experimenting with the idea of using multiple textboxes with the same class filled with different dropdown options that also have the same class. However, I am encountering some issues. When I click on a dropdown option, it changes the value in a ...

Is there a way to retrieve the timestamp of a DOM change event when using MutationObserver for event tracking?

Currently, I am successfully using MutationObserver to monitor changes in the DOM. However, I would like to include a timestamp for each event. Unfortunately, there doesn't seem to be a timestamp property available in the MutationRecord. https://deve ...

Avoid storing js files in cache during the development phase

When I use django runserver for development, I encounter the issue of my javascript file being cached. It's difficult to determine if the file is cached or not unless I manually add alert or console.log statements each time I make a change just to che ...

What causes the tweets' IDs to be altered by axios when parsing the response from the Twitter search API?

I am currently utilizing axios to send a GET request to the Twitter search API in order to fetch recent tweets that utilize a specific hashtag. To begin with, I ran tests on the twitter search API via Postman and noticed that the id and id_str tweet statu ...

Determining in Angular 8 whether a value has been altered by a user or by a method call

Within my select element, the value is currently being assigned through an ngOnInit call. Here is an example of the HTML code: <select name="duration" [(ngModel)]="exercisePlan.duration" (ngModelChange)="onChange($event)"> <option *ngFor="l ...

Having Multiple File Inputs [type=file] in one webpage

Is it possible to have two separate inputs for uploading images, each setting a different background image in a div? The second file input is: <input type='file' id='getval' name="logo" /> I want this file to be set as the back ...

Is there a way to detect when a user has recently updated their Chrome Extension in order to send them notifications?

I have implemented an info button in my extension, where a red dot appears on the top right corner to alert users of new updates whenever they update the extension. Currently, I achieve this by storing a row in localStorage when users view the updates. If ...

There are multiple ways to extract a value from Python code and assign it to a JavaScript variable in a JS file

I am currently working on developing the frontend for a voice bot using JavaScript, while the backend is written in Python. if hi == 0: talk('hello iam kavi') print('hello iam kavi Voice assistant') talk('How are you bu ...

Is there a way to schedule a function to run every 6 hours in node.js based on actual time instead of the device's time?

var currentTime = new Date().getHours(); if(currentTime == 6){ //function Do stuff } if(currentTime == 12){ //function Do stuff } if(currentTime == 18){ //function Do stuff } if(currentTime == 24){ //function ...

SASS - issue with font face not displaying correctly due to incorrect file path

I've recently delved into the world of SASS and I'm encountering a dilemma with importing two specific fonts: Montserrat and Open Sans. Typically, in regular CSS, you would use something like this: @font-face { font-family: 'Montserrat& ...