The clingy navigation bar hinders smooth scrolling to the content

My website has an image where users can click on elements to scroll down to text. However, I'm facing a problem because there is a sticky menu at the top of my website. How can I ensure that the scrolling works correctly with the sticky menu included?

An example HTML code (without the sticky menu) looks like this:

<!DOCTYPE html>
<html>
<body>
  
  
  <style>
    html{scroll-behavior:smooth}
  </style>


<div style="width:100%;">
    <img id="img_ID" src="https://i.ibb.co/M6pJRry/kalendarium-22.png" usemap="#map" border="0" width="100%" alt="" />
</div>
<map id="map_ID" name="map">
<area shape="rect" coords="81,79,171,117" href="#1954" />
...
...

<p id ="2018">
<strong>Powstanie polskiej marki NARUM.</strong>Michał Toczyłowski, prawnik i przedsiębiorca, szukając ratunku, dla jednego ze swoich synów, u którego zdiagnozowano zwiotczenie mięśni (skutek pewnych działań medycznych), trafia w rosyjskiej literaturze medycznej, na wzmiankę o niezwykłej bakterii Narine. Po wielomiesięcznych poszukiwaniach udaje mu się w końcu nawiązać kontakt z producentem w Armenii. Po doświadczeniu na sobie i najbliższych, niezwykłego działania probiotyku, postanawia sprowadzić te produkty na rodzimy rynek. Tworzy markę Narum i rozpoczyna współpracę z producentem z Armenii.
</p>

<br>


...

<script type="text/javascript">
window.onload = function () {
    var ImageMap = function (map, img) {
            var n,
                areas = map.getElementsByTagName('area'),
                len = areas.length,
                coords = [],
                previousWidth = 1900;
            for (n = 0; n < len; n++) {
                coords[n] = areas[n].coords.split(',');
            }
            this.resize = function () {
                var n, m, clen,
                    x = img.offsetWidth / previousWidth;
                for (n = 0; n < len; n++) {
                    clen = coords[n].length;
                    for (m = 0; m < clen; m++) {
                        coords[n][m] *= x;
                    }
                    areas[n].coords = coords[n].join(',');
                }
                previousWidth = document.body.clientWidth;
                return true;
            };
            window.onresize = this.resize;
        },
        imageMap = new ImageMap(document.getElementById('map_ID'), document.getElementById('img_ID'));
    imageMap.resize();
    return;
}
</script>
</body>
</html> 

JSFiddleDemo

The scrolling functionality works perfectly without the sticky menu. If you would like to see how it behaves with the sticky menu included, you can visit my website here.

Answer №1

The website is functioning properly in terms of scrolling. However, the presence of the navbar can be quite bothersome...

One possible solution is to insert an empty tag like a div, p, h1, etc., and assign it a specific id to help reduce the amount of scrolling on the page.

<a href="#SrcollId1">To Section 1</a>
<a href="#HigherLink">To Section 2</a>

<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>

<p id="HigherLink">-</p>

<!-- To ensure that this crucial text is not obstructed by the navbar, adjust the position of the <a> tag to higher up. -->

<p id="SrcollId1">>This is incredibly significant text that is being blocked by the navbar...</p>

<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>

Answer №2

An effective solution is to assign a class specifically for elements in your body that are being obscured by a menu. By determining the total height (margin + padding + height) of your fixed menu bar, you can then apply padding (with a value equal to the height of the menu bar) to all affected elements.

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

Canvas displaying inaccurately (unsteady)

While working on a simple HTML5/javascript game, I encountered an unusual issue with the canvas drawings - they seem to be unstable. I have a map that needs to be drawn in a specific way: The background consists of 2 layers: the ocean and the islands. Th ...

"Implementing JQuery addClass Functionality to Enhance Menu Sty

I've created a menu that is stacked on top, with the "Representaciones" section shown on the same page below a welcome image. However, when I click on it, everything works fine but if I refresh the page, the "selected" class disappears from "represent ...

Pass PHP date to JavaScript and increase its value

I'm looking to retrieve the server time with PHP and store it in a JavaScript variable. Once stored, I'd like it to continuously increment. Below is the code snippet: function initTime(date){ var today=new Date(date); var h=today.getHours(); v ...

List application now includes the capability of adding three items in one go, rather than just one

Furthermore, when the script is placed in the same file as the html, it results in the addition of two items simultaneously instead of three. var itemNum = 1; $("document").ready(function() { $("#addCL").click(function() { var itemId ...

Challenges in displaying a preview of the cart following a successful ajax request

I'm trying to display a cart preview when hovering over a specific shopbag div. To achieve this, I've created another div called livebag where I run a query to fetch and preview the cart items stored in the database. Initially, the livebag div is ...

What is the best way to add HTML tags both before and after a specified keyword within a string using JavaScript?

Imagine I have a string similar to this, and my goal is to add html tags before and after a specific keyword within the string. let name = "George William"; let keyword = "geo"; Once the html tags have been appended, the desired result should look like ...

What could be causing this highchart plot to fail to display in both IE and Chrome?

Check out the plot in this jsfiddle: http://jsfiddle.net/essennsee/y5HCm/ The plot looks good in Firefox, but only shows the legend in IE and Chrome. If I remove the following code snippet it works fine. Is there a different way to format the labels?: ...

Utilizing the Vuetify pagination feature in your project

I am in need of some guidance regarding the configuration of vuetify pagination. I have a card component that I loop through, but I also want to implement pagination around it. Any insights on where to start would be greatly appreciated? <v-pagination ...

Can ChatGPT Service Error be resolved?

I tried using chatGPT to help me with my HTML code, but every time I opened it I received an error message saying "Failed to get service" Here is the code that I want to make work: <html> <head></head> <body> <script& ...

Integrating Javascript and JQuery in Reactjs: A Comprehensive Guide

Currently, I am working with ReactJS and utilizing the Next.js framework. My goal is to implement the provided code snippet in index.js to display data (day, month, etc.). How should I go about achieving this? Here is the code snippet: <script> fun ...

Incorporating a partial view within a view through AJAX requests

I am attempting to update a partial view within a view upon form submission, but I am facing issues where the partial view renders as a normal view instead. Can anyone help me identify the mistake in my code? Controller: public ActionResult ChangeHeatNam ...

Can you recommend any open source projects with exceptionally well-written Jasmine or Jasmine-Jquery tests?

Currently, I am in the process of learning how to test a new jquery plugin that I plan to develop. I'm curious if there are any notable Github projects like Jasmine or Jasmine-jquery with impressively crafted Jasmine tests that I could explore for in ...

Run a Python script to capture mouse coordinates using Selenium

Greetings, I am currently utilizing selenium webdriver to retrieve the X,Y coordinates of the cursor at a specific moment on the webdriver screen. However, I am facing challenges with the implementation of a method that involves using driver.execute_script ...

Tips for effectively displaying HTML data from a database on a web browser

Storing html data in a database is a common practice for many web developers. The html data generated by a wysiwyg editor is typically simple and straightforward. Prior to storing the html data in the database, it is essential to run it through HTMLPurif ...

Selling beyond webpack's confines

Today I had an interesting thought and couldn't find much information on it, so I decided to share some strange cases and how I personally resolved them (if you have a better solution, please feel free to comment, but in the meantime, this might be he ...

Counting endlessly with an increase of two decimal places

I am attempting to create an endless counter that begins at 10.41 and increments by 10.41 every second. Despite searching through numerous tutorials, I have yet to find one that accommodates the increase with a decimal number unit of 10.41 every second. ...

Transforming this Rails form into an Ajax/JavaScript/jQuery format will eliminate the need for submission

I have developed a form in Rails that computes the Gross Profit Margin Percentage based on an input of Price. When a user selects the relevant product on the form and enters a price in the 'deal_price' field. A callback is triggered to retrieve ...

Customizing skin CSS for DNN Portal and Page images

Currently, I have a unique custom skin that I personally created. It is implemented on multiple portals that I am responsible for managing. My goal is to incorporate the ability for the header image to change based on the specific page being viewed. The he ...

Creating a new session in Node.js for every request

Our team is currently developing a nodejs application that requires the maintenance of sessions. We have implemented express to handle node variables, but we are facing an issue where a new session is created every time we hit a new service. The structure ...

Is there a way to retrieve the request object within loopback operational hooks?

I am currently utilizing loopback 3.x and have created an Access Hook within my code. My goal is to include a condition based on the User Agent. Specifically, I am looking to access Request > Headers > User-Agent. Is it feasible to retrieve this in ...