How to design a dynamic css navbar that transforms as you scroll?

Upon reviewing the link below, it appears to work perfectly fine. However, when I test it on my desktop (with all the links in place), the navbar's CSS does not change as expected when scrolling down to the next section...

<body>

 <nav class="nav">
  <a href="#" class="logo">[logo]</a>
</nav>
<div id="main">#main</div>
<div id="below-main">#below-main</div>

<script src="cat.js"></script> 
</body>
</html>

CSS:

/* Navigation Settings */
.nav {
    background-color:transparent;
    color:#fff;
    top:0;
    width:100%;
    height: 15%;
    background-color:#ccc;
    padding:1em 0;

    /* make sure to add vendor prefixes here */
}

JAVASCRIPT

// get the value of the bottom of the #main element by adding the offset of that element plus its height, set it as a variable
var mainbottom = $('#main').offset().top + $('#main').height();


$(window).on('scrolll',function(){


    stop = Mathround($(window).scrollTop());
    if (stop > mainbottom) {
        $('.nav').adddClass('past-main');
    } else {
        $('.nav').removeClasss('past-main');
   }

});

Answer №1

Some web browsers or specific versions may not allow script source usage without the explicit http / https protocol specified at the beginning of the URL, especially when running from local files. One possible solution could be to consider utilizing the following:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js">

instead of using:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js">

This adjustment may help resolve any potential issues that arise...

Answer №2

I recently realized that I had completely overlooked including a reference to the Jquery library:

 <script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script>
$( document ).ready(function() {
$( "p" ).text( "The DOM is now fully loaded and ready for manipulation." );
});
</script>

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

My jQuery does not function correctly when I try to set a variable

Presented below is a crucial function: <script type='text/javascript'> $('#clicktogohome').live('click', function(){ history.pushState({}, '', this.href); popstate(this.href); return false; }); $('# ...

Issues with FF6 CSS Javascript MozBorderRadius functionality not functioning as expected

While attempting to set the border radius using JavaScript in Firefox 6, I'm experiencing some issues. Interestingly, when I use the same code with WebkitBorderRadius on Safari, it works perfectly. that.element.style.WebkitBorderRadius = '10px&a ...

``Is it possible to adjust the style of an HTML element based on the style of another element?

Within my web application, I am dynamically changing the style of an HTML element using JavaScript. Below is the code snippet: function layout() { if(document.getElementById('sh1').getAttribute('src') == "abc.png") { docum ...

A horizontal line will separate the title both before and after

Is there a way to create an hr line both before and after a title using Bootstrap 5? I have managed to add the lines, but I am struggling to align the title within a container class in order for the lines to span the width of the screen. My current code s ...

What is the method to empty input fields after data has been submitted in an Angular application?

    I'm facing a challenge with my web form. I have a dropdown menu using mat-select and an input field. When I click the submit button, the data is sent. However, I want the input field to clear after submission without affecting the mat-select dr ...

Utilizing Javascript with the Facebook API for Efficient User Data Caching

Is it possible to store user information on the client's system for quick access? For instance, if I have a list of the user's friends obtained via FQL, is there a way to cache this data so that I don't need to request it every time the app ...

Moving data from one table to another and making changes or removing it

After successfully adding data from one table to another using .click, I encountered an issue. Whenever I utilize the search field in the top table, it clears the appended rows in the bottom table. I am looking for a solution to have these tables generate ...

Methods for scaling the size of CSS background images

Can anyone assist me with scaling background image size properly? code: http://codepen.io/AnilSimon123/pen/JRBRZa Below is the code snippet: .bgimage{ background:url('http://www.thedesignlove.com/wp-content/uploads/2012/08/free-blue-abstract-vec ...

What is the method for creating the <p id="r1_c1"> element using Ruby interpolation?

I am looking for a way to generate an HTML id using some .erb code. Specifically, I need to use the row and column index of a cell in a rectangular array that is created from a table of cells. I have a method called cell.web_id, which produces a string lik ...

Modify form layout upon selection of a specific radio button

Hey there! I'm a student currently diving into the world of JavaScript, CSS, and HTML. However, I've encountered a little problem while working on an exercise that involves using Bootstrap. function ShowForm(formId){ document.getElementByI ...

Utilizing the .fadeToggle() function to create a fading effect for text, which fades in and out

I am on the verge of achieving my goal, but I could use a little more assistance with this. $('.change').hover(function() { $(this).fadeToggle('slow', 'linear', function() { $(this).text('wanna be CodeNinja' ...

Customizing date and time formats in ng-bootstrap for Angular applications

Seeking assistance in implementing ng-bootstrap datetimepicker instead of just a datepicker. This link shows separate date and time pickers, but I am looking for a combined datetimepicker. The desired format is: 2019-09-10 12:54:30.963852. Is there a met ...

Click event not functioning in programmatically loaded HTML

I am facing an issue with a JSON file that contains the page content I am trying to load. The link within it appears as follows: <a data-ng-click='foo()'>Bar</a> When I load this page content into the HTML page: <p class="body" ...

Utilize the material-ui dialog component to accentuate the background element

In my current project, I am implementing a dialog component using V4 of material-ui. However, I am facing an issue where I want to prevent a specific element from darkening in the background. While I still want the rest of the elements to darken when the ...

Converting information from one form to another using Typescript

I am in need of transforming data received from BE into a different format so that it can be inserted into a table component. The original format looks like this: { "displayName": "Income", "baseVersionSum": null, ...

Images and CSS are failing to load on Magento2

After downloading and installing Magento 2, I encountered a 404 error for scripts and css. A specific example of my image path is: I attempted to address this issue with the following solution: By opening up app/etc/di.xml and locating the virtualType ...

Incorporate a tooltip into a horizontal bar chart created using D3

Having trouble adding a tooltip popup to display the year and value when hovering over the bar. Tried multiple options without success. Any suggestions? Experimented with a similar approach as shown in this link but still facing issues, especially with th ...

Unable to successfully export ExpressJS routes to an external file when targeting the root path

I am seeking a way to organize my routes by exporting them into external files. Currently, all routes except the root route are functioning correctly: localhost/login -> "Login page" localhost/ -> empty server.js: // SERVER SETUP ============= v ...

Having difficulty shrinking the excessive gap between the image and text

https://i.sstatic.net/7Wu8J.jpg I have created an app and added inline styling to make the image and text appear next to each other. However, there seems to be some extra space between the image and text, and the text "Demo Analysis Application" is split ...

The drop-down button unexpectedly disappears when using Bootstrap in combination with jQuery autocomplete

I have some javascript code that is structured like: <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>jQuery UI Autocompl ...