Does the header show up when you scroll?

Recently, I encountered a project where I needed a different header to appear when the page was scrolled past the main one.

If you want to check out my code, here's a link to a fiddle:

https://jsfiddle.net/a7tLdsov/3/

I've tried some JavaScript to make it work, but it's not quite there yet. Can someone guide me on how to achieve this?

Thanks in advance!

:)

Answer №1

Consider these modifications:

Replace

$("body").scroll

with

$(window).scroll

and update

document.getElementById('transhead').style.display = "visible";

to

document.getElementById('transhead').style.display = "block";

Ensure jQuery is included as a framework in your code snippet.

Check out the updated fiddle: https://jsfiddle.net/hba9twcd/

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

Update the div content to completely replace it with fresh data using Ajax

I'm currently working on implementing a currency switcher feature for my website, allowing users to toggle between two different currencies. The site is a reservation platform with a booking form displayed on the left side and the booking details occu ...

Experiencing a problem with a loop in iMacros/JS?

I have an iMacros/JS script for Facebook that logs into a FB account from a CSV file, then it has a second loop j which sends 20 friend requests from each account. The issue arises when switching accounts and encountering a popup message requiring phone n ...

"Why isn't my variable working for the address when trying to append an image source using jQuery

Currently, I am using jQuery to add a variable from nodeJS/MongoDB that contains the address of a profile picture. For example: profile_pic-1512068176863.gif. My issue is that when I directly copy and paste this value into a string, the image displays with ...

Is there a way to pause the slideshow? Are there any ways I can enhance the code to make it more efficient?

Currently, I am testing a slideshow that automatically transitions every 1 second. I have set it up to pause when it reaches the first image. However, when it stops on the initial image and I click the next button, nothing happens. If I try to interact wit ...

Utilizing jQuery AJAX to enable a functional back button feature upon modifying HTML

While there are numerous inquiries regarding jQuery and Back button issues, the focal point is typically on maintaining history features when using the browser back/forward buttons. One specific query I have is how to load an AJAX-affected HTML page when ...

Using Jade language in a standard web application without the need for Node.js

Can Jade be utilized in a traditional web application without reliance on Node.js? This question might seem unconventional considering Jade is built for Node, but I'm curious to know if its functionality can extend beyond the Node environment. ...

Combobox fails to dynamically update

Currently, I am attempting to create a dropdown menu that dynamically updates based on changes made in another dropdown menu. Despite my efforts, I have not been able to find a suitable solution and feel quite lost at this point. In an attempt to troubles ...

Instructions on how to position the footer below the content and make it show inline

This question seems to be a duplicate, with only one unanswered answer and no discussion. The original poster did not confirm if the solution worked. I have tried the suggested CSS but it does not solve my problem, which I believe is the same. My layout i ...

What is the best way to divide an array of objects into three separate parts using JavaScript?

I am looking to arrange an array of objects in a specific order: The first set should include objects where the favorites array contains only one item. The second set should display objects where the favorites array is either undefined or empty. The third ...

What are some ways to connect my CSS styles without encountering a MIME error?

Working on a Nodejs - Express - Vanillajs project, I encountered an issue when testing my routes. The index page failed to load CSS, displaying the following error message: Refused to apply style from 'http://localhost:3000/public/css/bootstrap.min. ...

Unable to retrieve array using $resource functionality

Having trouble retrieving an array using $resource. Can anyone assist me with this? It works fine when I use $http Encountering an error in the console: TypeError: undefined is not a function at http://127.0.0.1:9000/bower_components/angular-resource/ang ...

Comparison between SSD and HDD animation speed in web hosting environments

I am currently in search of a web hosting provider for a website I have created. The site features some performance-heavy animations, particularly due to a fullscreen slider with filter and scaling transitions. I need a provider that can ensure optimal per ...

Combining Multiple Collections in Meteor.js and MongoDB: A Comprehensive Guide

My inventory consists of various items. With an overwhelming number of products, I aim to categorize them for a more efficient organization of my publish/subscribe code (and subsequent updates to templates). Let's say I have 4 separate collections i ...

Update the HTML body table by duplicating the element

On my HTML page, the body includes a table with data in each cell. I also have another similar page, but this one doesn't have any data in its table cells. Whenever I add a value to a cell on the first page, it sends a POST call to update the data in ...

Trigger a function in jQuery when an input field is focused

Whenever I click on a text input field, a json request is triggered which retrieves some data. $("input").one('focus', function(){ var thefield = $(this); $.getJSON("http://www.blabla.com/bla", function(data){ alert(JSON.stringify(da ...

Display a JavaScript dialogue box containing a PHP variable

Is there a way to display the correct JavaScript box when using a While loop in PHP? Here is the code snippet: while($result= mysql_fetch_array($data)){ <tr class="<?php echo $style;?>"> <td><?php echo $result['commis ...

What is the best way to utilize Node.js to serve a single page HTML file on port 80?

This is how my project structure is organized: project assets/images/ css/application.css js/application.js font node_modules index.html server.js package.json I am aiming to run 'node server.js" in the project directory and have it serve on port ...

Using jQuery's ajax function to send data with a variable name of data field

I am trying to figure out how to dynamically add a variable to the name of the data field I want to send information to through ajax. Below is an example of the code I'm working on: var qty = $('#qty_'+value).val(); $.ajax({ url: &apo ...

Creating a jQuery AJAX call with a vanilla JavaScript promise

I recently transitioned my website to a Single Page Application (SPA), which involves working with only one HTML page populated using JavaScript. In order to simplify the process, I decided to consolidate my JavaScript files into one. However, while creati ...

The default action is not triggered when the click event occurs

Hey there, I have been working on this <ol> list of events using jQuery (version 1.4.2). Everything is set up within the $(document).ready() function. Something strange is happening where when I click on the <li>, it triggers a click on the co ...