Elevation navigation bar shift connections

I created a JavaScript navbar transition that changes the background color of the navbar as you scroll down. Everything seems to be working fine except for the navbar links. I assigned a new id to the links, but only the first link changes color and the others do not.

    var topbar, containtogrid, menulink, yPos;
function yScroll(){
    topbar = document.getElementById('topbar');
    containtogrid = document.getElementById('containtogrid');
    menulink = document.getElementById('menulink');
    yPos = window.pageYOffset;
    if(yPos > 150){
        topbar.style.backgroundColor = "#484848";
        containtogrid.style.backgroundColor = "#484848";
        menulink.style.backgroundColor = "#484848";
    } else {
        topbar.style.backgroundColor = "#00A7B7";
        containtogrid.style.backgroundColor = "#00A7B7";
        menulink.style.backgroundColor = "#00A7B7";
    }
}
window.addEventListener("scroll", yScroll);

Here is the code: http://codepen.io/anon/pen/vEgVQy. I am using Sass, which is why there is a lot of CSS - just scroll down to the end of the CSS section.

Answer №1

I decided to take your codepen and fix the transition issue that was bothering you.

Here are the steps I followed:

  1. First, I removed the id #menulink from the navbar links. Remember, IDs should be unique to each element on a page.
  2. Next, I made the background color of the links transparent to allow the color change of the topbar to show through.
  3. I got rid of the JavaScript code associated with elements having menulink IDs since those were no longer in use after removing them from the HTML.

In my version on codepen, the transition works smoothly. However, for the best outcome, you may want to make adjustments to the mouseover styles and dropdown elements as well.

I hope these changes help you achieve the desired effect!

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

Unlock the power of Redux: Crafting specialized selectors with parameters

I am currently working with a state that contains a map array of data. I find myself needing to select a single object from this array. To achieve this, I can retrieve the entire array in my component using: function mapStateToProps (state) { return { ...

Retrieve JSON information using asynchronous JavaScript requests

I am currently working on pulling JSON data via ajax. While I am successful in retrieving data from the first 2 items, it is the information under "placemark" that I urgently require. My goal is to present this data in a list format similar to an RSS feed. ...

Alignment of Image and Font Menus in a Vertical Layout

While I've been using WordPress for a considerable amount of time, it's important to note that my coding skills are limited. I typically rely on themes and make customizations as necessary rather than building from scratch. When faced with challe ...

Looking for guidance on where to find a functional code sample or comprehensive tutorial on working with ViewMetadata in Angular2

I am currently trying to understand the relationship between viewmetadata and the fundamental use of encapsulation: ViewEncapsulation, including ViewEncapsulation.Emulated and ViewEncapsulation.None. Here is a link for further information: https://angula ...

Is it possible to ensure that the image stays within the viewport when using a CSS image popup on hover?

I need a solution for ensuring that the full thumbnail image stays within the viewport when hovering over a link on my page. Below is the current code I am using to create this effect: HTML: <span class="popup-wrap"> <a class="po ...

Issue with Selenium: Unable to select the WebElement

I am a beginner with selenium and I have encountered a problem while trying to click on a specific element using the following locators. Unfortunately, none of them seem to work as expected and my scripts just skip over that particular line without any err ...

Determine whether a checkbox is checked or not using jQuery/ES6

Here is my jQuery code attempting to determine whether the checkbox has been clicked. I have tried using both is and prop, but it always shows as false or undefined in the console. Please advise on what might be going wrong here. Additionally, I would lik ...

Looking for an instance of a node.js ftp server?

I'm facing a challenge in creating a node.js application that can establish a connection with an FTP server to download files from a specific directory: Despite attempting to follow the instructions provided in the documentation for the ftp npm packa ...

NextJS hot reload with Docker is a powerful combination for seamless development environments

I've encountered issues trying to configure hot reload with Docker and NextJS. When I make changes and save a file, the server does not reload. Below is the contents of the docker-compose.yml: version: '3' services: mainapp: build: ./ ...

Mapping drop-downs based on the length of a JSON array

Looking to generate dropdowns in a React Native mobile application based on the length of values in an API JSON array. Here's an example of the desired output: eg:- Choice 1 (Label of the Drop Down) -Sub Choice 1 . (Value Data) ...

Adjust the size of the div to match its parent's size when resizing

Can a div be resized to match its parent's size on window resize? Here is the current HTML code: <div class="sliderContainer"> <div id="cyler"> <div class="cy1" style="background-image:url(images/Keggy_Banner_Ie.jpg); back ...

I need help figuring out how to retrieve the full path of an uploaded file in JavaScript. Currently, it only returns "c:fakepath" but I need

Is there a way to obtain the complete file path of an uploaded file in javascript? Currently, it only shows c:\fakepath. The file path is being directly sent to the controller through jquery, and I need the full path for my servlet. Are there any alte ...

How can I include JavaScript files in Maya or 3DS Max?

My dilemma lies in attempting to access a js file on Maya (2013) and 3ds max (2016) without any available three.js importers for these particular softwares. How can I effectively import a js file on either Maya or 3ds max? Alternatively, are there other ...

How to Include CSS Folders in Angular 6's angular.json File

I am in the process of converting my HTML template into an Angular app. In my project, I have a CSS folder named plugins and an image folder. However, when I try to add the following code snippet to the angular.json file: "styles": [ "src/asse ...

What is the best way to include React globally when running unit tests?

In my Rails project, I have integrated the react-rails gem, which sets up a global variable like this: window.React = React; While this is convenient for regular usage, it causes issues when running unit tests with Jest because the global React variable ...

Querying mongoose with $near or other fields

I'm trying to retrieve documents using a query $or on different fields along with a $near query that is causing issues. Schema locationSchema{ ... beacon: String, access_point: String, gps: [], ... } locationSchema.index({ gps: ...

The orientation change listener seems to be unresponsive on iOS devices, while it functions properly on Android devices

I encountered an issue with a code snippet I am using: window.addEventListener("orientationchange", orientation); Interestingly, the function orientation() is not being triggered on an iPhone SE running iOS 10.3, but it does work on a Moto G running Andr ...

Utilizing BootStrap 4 to ensure uniform image sizes within a row of columns

I'm facing a challenge in creating a row of 4 images that are responsive and uniform in size, despite being different dimensions (640x799, 640x479, ...). I've attempted to use columns and img-fluid to achieve this, but the shorter images do not f ...

Working with a collection of JSON objects

Simply put, I have an array of JSON objects without keys. My goal is to pass each object through HTML, but there is redundant data that I want to combine. The array is obtained via an AJAX call, and I am unsure whether to address this during or after the c ...

Is it possible to programmatically set focus on a DOM element using JavaScript or jQuery?

My code dynamically loads select boxes based on user selections. I have a specific instruction to select an option, which looks like this: //returns a string of <option>s by ID $('#subtopic_id').load('ajax.php?f=newSubtopic&am ...