header is fixed and a panel slides down and remains fixed while scrolling down the page

I am encountering difficulties while trying to implement a fixed header with a slide-down panel that also remains fixed as you scroll down the page. Currently, when the slide-down panel is open, the page content scrolls under the header. However, I want the slide-down content/form to stay fixed in its position when active so that only the page content scrolls.

// CSS for the slide-down panel    
#sliding_panel {
background: #6C9D30;
height: 0;
position: relative;
overflow: hidden;
-webkit-box-shadow: 0 0 15px rgba(0, 0, 0, 0.4) inset;
-moz-box-shadow: 0 0 15px rgba(0, 0, 0, 0.4) inset;
box-shadow: 0 0 15px rgba(0, 0, 0, 0.4) inset;
color: #fff;
}

// CSS for the fixed header
header#header {
position:fixed;
width: 100%;
height: 100px;
background: rgba(0,0,0,0.5);
z-index: 1;
}

Answer №1

It appears that there is a semi-transparent header on your website, allowing text to scroll underneath it. I have created a simple example of a fixed header with a sliding panel for you to review.

var context = $('#header');

context.find('.togglePanel').on('click', function (e) {
    e.preventDefault();
    context.find('#sliding_panel').show();
    context.find('.togglePanel').hide();
});

context.find('.togglePanelClose').on('click', function (e) {
   e.preventDefault();
   context.find('#sliding_panel').hide();
   context.find('.togglePanel').show();
});

        
   
body {
  height: 100%;
  margin:0;
}
#sliding_panel {
  background: #6C9D30;
  height: 50px;
  position: relative;
  overflow: hidden;
  -webkit-box-shadow: 0 0 15px rgba(0, 0, 0, 0.4) inset;
  -moz-box-shadow: 0 0 15px rgba(0, 0, 0, 0.4) inset;
  box-shadow: 0 0 15px rgba(0, 0, 0, 0.4) inset;
  color: #fff;
  margin-top:80px;
  display: none;
}

header#header {
  position:fixed;
  width: 100%;
  height: 100px;
  background: #ccc;
  z-index: 999;
  top:0;
}
a.togglePanel {
  text-decoration: none;
  text-align:center;
  margin: 20px auto;
}
.content {
  padding-top:100px;
  line-height:90px;
  z-index: 888;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<body>
    <header id="header">
        <a href="#" class="togglePanel">Open panel</a>
        <div id="sliding_panel">hello there!
             <a href="#" class="togglePanelClose">Close panel</a>
        </div>
    </header>
    <div class="content">
        this is some text ... <br>
        this is some text ... <br>
        this is some text ... <br>
        this is some text ... <br>
        this is some text ... <br>
        this is some text ... <br>
        this is some text ... <br>
        this is some text ... <br>
        this is some text ... <br>
        this is some text ... <br>
        this is some text ... <br>
        this is some text ... <br>
        this is some text ... <br>
        this is some text ... <br>
        this is some text ... <br>
        this is some text ... <br>
        this is some text ... <br>
        this is some text ... <br>
    </div>
</body>
</html>

Cheers

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

In Angular.js, there is a limitation with ng-keyup where event.preventDefault() cannot be utilized, and ng-keypress may have delays when updating the value for an

Issue: The input type number with min and max constraints is not being enforced while typing in the input box. It allows values outside of the specified range to be entered. However, using the arrow buttons of the input type number works fine. Solution Ne ...

The iOS app icon for React Native is not appearing on the screen

After using XCode 12, I encountered an issue while trying to archive my iOS app. Despite no errors and no issues with app assets, the app icon mysteriously fails to show up. I've tried various solutions, including modifying codes in the pod file and r ...

What is the reason behind the animation being refreshed when using slideToggle() in jQuery?

Recently, I managed to position a fixed div at the bottom of the viewport to serve as a contact tab. When this tab is clicked, it smoothly triggers a panel to slide out, which is functioning correctly. However, I'm faced with the challenge of making ...

Sorting data with a specified range in jQuery DataTables

Check out this functional example for sorting a table with column sorting capabilities. Preview Here $(document).ready(function() { // Setting up - adding a text input to each footer cell $('#searchresults thead tr').clone(true).appendT ...

Transfer only certain directories located within the primary directory

Imagine having a main-folder, which contains folders of type my-folder-x. Within these my-folder-x folders, there are subfolders and files. -main-folder -my-folder-a -build-folder -demo-folder dummy.js dummy.css my.json -dummy-folder - ...

How can I modify the default color in Google Charts Geomap?

I'm looking to customize the chart region color to a specific shade instead of the default yellow. Currently, I have only been able to change the marker color using the provided code to generate the chart data: dataTable = new google.visuali ...

When attempting to invoke the rest function, an error occurs stating that the dataService.init in Angular is not

Learning AngularJS has been my current focus. To practice, I have been working on a Quiz app tutorial. However, I encountered an issue when trying to call the rest function of a factory after injecting it into one of my controllers. The JSON data for this ...

Adding dots between page numbers when using ReactJS/Javascript Pagination can be achieved by implementing a specific method

I have created a pagination component using React JS. Currently, it only displays all the page numbers, but I want it to show dots when there are more than 8 total pages. Here's how I envision it: c. When total is less than 9 pages: Page 1 selecte ...

Implementing Vue's dynamic component addition feature

I recently came across an interesting article on dynamically adding different components in Vue. The article explains a good method for binding different components to tabs, but I have a specific requirement. I want to bind one type/name component that wil ...

Unable to access class instance from event handler in Angular 2 and Typescript

In the scenario I'm working on, I need to dynamically add multiple instances of a child component to a template. Each of these child components emits a 'select' event, and each one requires a different event handler within the parent compone ...

Utilizing Handlebars and Bodyparser in Node.js

For this simple project, my goal is to collect user input using 'body parser' and display that input on the index page using handlebars. I've made multiple attempts but haven't been successful yet. I'm unsure if handlebars and body ...

Attempting to employ the .reduce method on an object

Currently, I am faced with the task of summing a nested value for all objects within an object. The structure of my object is as follows: const json = [ { "other_sum": "1", "summary": { "calculations" ...

Utilizing website analytics to capture video recordings

I've meticulously saved the coordinates and time-stamps of each mouse movement on a webpage, along with the site's document and other important data. With this information in hand, how can I utilize it to create a captivating screen cast or video ...

Generating an Array of Meshes Using Objects in THREE.JS and GLTF Format

Here is the code snippet I have for loading a mesh onto an object. Currently, it is iterating through the entire mesh. Code snippet: var loader = new THREE.GLTFLoader(); loader.load( '../gtf/Box.gltf', function ( gltf ) { ...

"Attempted to load dataTable. AJAX request was successful, however no data is currently displaying

How can I utilize server-side processing to load JSON data in a dataTable? I am working on a custom WordPress plugin where I need to display data from wpdb within a dataTable. Although my AJAX call is successful, the dataTable only displays a "Processing. ...

Error encountered: Multer TypeError - fields does not have a function called forEach

I'm currently working on a metadata reader using multer in node.js with express on c9. I've spent some time searching for solutions to my issue, but it seems like no one else has encountered the error I am facing: TypeError: fields.forEach is no ...

Promise.all doesn't pause for Firestore queries to iterate

The code I am converting from the Realtime Database to Firestore involves looping through each User (doc) in Firestore and then through each document of 2 nested Subcollections inside each User in order to create some jobs to be handled later. Although I ...

The tab key seems to be malfunctioning when triggered during a jquery change event

I encountered an unusual issue with my jQuery events, and I'm not entirely sure if it's a problem related to jQuery. In hopes that some jQuery experts can shed some light on this. The code snippet below was included in my HTML page to automatica ...

A guide on extracting text enclosed by <a> and </a> tags using regular expressions

I have come across the following code: <a align="center" href="http://google.com"><b>Google Link<b></b></a> <a align="center" href="http://yahoo.com"><strong>Yahoo Link</strong></a> Now, I am looking ...

Can a variable be assigned based on the current route being accessed?

Currently, I am using a sidenav component with the following structure: <MenuItems> <NavLink to="/contacts/new">New</NavLink> <NavLink to="/contacts/list">New (all)</NavLink> <NavLink to="/con ...