(Applied jQuery) Trouble with div height in responsive layout

I have created jQuery full-page sliding panels that work perfectly on desktop devices. However, when the browser window is resized smaller, the panel divs fail to fill the page.

If you want to view the issue in action, you can check out the JSFiddle demo here and resize the preview window down: Fiddle

HTML:

<div class="window">
<div class="panel-1" id="one">
    <p>Lorem</p>
    <div class="nav">Jump To:
       <a href="#" id="1one">1</a>  <a href="#" id="1two">2</a>  <a href="#" id="1three">3</a>
    </div>
</div>
<div class="panel-2" id="two">
    <p>Lorem</p>
    <div class="nav">Jump To:
        <a href="#" id="2one">1</a>  <a href="#" id="2two">2</a>  <a href="#" id="2three">3</a>
    </div>
</div>
<div class="panel-3" id="three">
    <p>Lorem</p>
    <div class="nav">Jump To:
        <a href="#" id="3one">1</a>  <a href="#" id="3two">2</a>  <a href="#" id="3three">3</a>
    </div>
</div>

CSS:

body {
     margin:0;
     padding:0;
 }
 .window {
     width: 100%;
     margin: 0 auto;
     overflow: hidden;
     position: fixed;
 }
 [class^="panel"] {
     height: 100%;
     text-align: center;
     position: absolute;
     transition: all ease 1s;
     -o-transition: all ease 1s;
     -moz-transition: all ease 1s;
     -webkit-transition: all ease 1s;
 }
 .panel-1 {
     background: gray;
 }
 .panel-2 {
     background: GoldenRod;
     margin-top:100%;
 }
 .panel-3 {
     background: green;
     margin-top:100%;
 }

JS (jQuery):

// Controls panel movement
$(document).ready(function () {
    // Add your JavaScript code here
});

// Ensures the "window" <div> fills the entire page height
$(function () {
    $('.window').css({
        'height': (($(window).height())) + 'px'
    });
    $(window).resize(function () {
        $('.window').css({
            'height': (($(window).height())) + 'px'
        });
    });
});

If anyone has insights or suggestions, please feel free to share! You can also access the JSFiddle demo again for reference: Fiddle

Answer №1

The reason for the issue you are experiencing is due to using margin-top to animate and position the panels on/off screen. Instead, consider utilizing the top declaration for better results:

$(document).ready(function () {
    $('#1two').click(function () {
        $('.panel-2').css('top', '0');
    });
    $('#1three').click(function () {
        $('.panel-3').css('top', '0');
        $('.panel-2').css('top', '0');
    });
    // Other panel click events
});

Remember to make necessary adjustments in your CSS as well:

.panel-1 {
    background: gray;
}
.panel-2 {
    background: GoldenRod;
    top: 100%;
}
.panel-3 {
    background: green;
    top: 100%;
}

.nav {
    background: black;
    color: yellow;
    bottom: 0;
    position: absolute;
    width: 100%;
}

Check out the updated Fiddle here.

Answer №2

Hey there, I've made some updates to the fiddle. Take a look and see if it functions as expected.

You can view it here

 .nav {
background:black;
color:yellow;
bottom:0;
position:absolute;
width:100%;

}

You can also check out the Shuffle animation version:

Visit the JS Fiddle link

Answer №3

It seems that the height of the div is fine, however, in order to position your .nav element at the bottom, you should follow this example: Click here

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

I encountered some problems with conflicting Angular dependencies, so I decided to delete the node_modules folder

An error has occurred: The module 'H:\All_Files\Scripts\Angular\example\node_modules\source-map\source-map.js' could not be found. Please ensure that the package.json file contains a correct "main" entry. ...

Why is the ID not being sent after a successful AJAX call using jQuery?

I'm currently utilizing JQuery to initiate an AJAX call for deleting data from a database based on ID. Here's how it's done: $(".delete").live('click', function(event) { var item = $(this), ...

Strange Actions with JQuery Drag-and-Drop Functionality

Apologies for my limited experience with JQuery UI, but I am in the process of creating a web-based chess engine for 2 players using JavaScript. Instead of point and click, I have decided to implement a user-friendly drag and drop feature for non-mobile us ...

Repeat the execution or refresh an EventListener

I am a beginner in the world of coding, currently working on my inaugural project to create a web-based game using HTML, CSS, and JavaScript. I have encountered an issue with the .addEventListener() method that I couldn't seem to find a solution for ( ...

What is the best way to store chat messages in a React application?

My idea for a chat application using React involves saving chat messages in localStorage. Below is the code snippet that illustrates this functionality: const [textMessages, setTextMessages] = useState([]); const [textValue, setTextValue] = useState(' ...

What are the advantages of using history.push or another method from react-router-dom compared to simply assigning the path to window.location.pathname?

When I need to navigate within my code, I find it more convenient to simply assign the desired path to window.location.pathname. Can this approach have any drawbacks? ...

Dealing with GraphQL mutation errors without relying on the Apollo onError() function

When managing access to an API call server-side, I am throwing a 403 Forbidden error. While trying to catch the GraphQL error for a mutation, I experimented with various methods. (Method #1 successfully catches errors for useQuery()) const [m, { error }] ...

Transforming JavaScript information into PHP with ajax for WordPress plugin creation

I'm currently navigating the realm of creating my inaugural WordPress plugin and encountering a hurdle in transposing a Javascript array of objects into PHP. My aim is to utilize this data to craft individual tables within the wp-admin user interface. ...

The method of altering a menu link in WordPress using jQuery varies according to whether the user is logged in or not

I need to update the last link on my menu. When a user is logged in, it should display a profile link; otherwise, it should show a sign-up link. ...

Numerous attributes for displaying ngOption values

I have an item that resembles the following: $scope.team = [ { name: "John", number: 1 }, { name: "Emma", number: 2 } ]; Currently, in my HTML code, I am using ngOption to populate a dropdown menu with values from the object. < ...

Is there a way to combine fixed and dynamic size elements within a flexbox container?

Currently, I am working on creating a layout that combines the automatic sizing feature of flexbox with fixed-size elements: <View style={{ height: 70, alignItems: "center" }}> <Text style={{ flex: 1, textAlign: "right", paddingRight: 10 }}&g ...

"Declare the Status, Refresh the Page, and Specify the Web

After refreshing the page, I am facing an issue where the text corresponding to the current URL is not being displayed. My application consists of a Main component that renders a MiniDrawer component containing a NavLink, followed by routing with the Route ...

Creating objects with variable-dependent values in node.js

I'm currently working on creating a user database in an object to assign values to each user, but I'm struggling to find a way to accomplish this. I attempted using var data = {} and then eval(`data.user_${user} = value`), however, it only write ...

The issue with the modal jQuery in Bootstrap 4 persists

Having an issue with my jQuery code. The problem is that when I click on the link, the modal opens but I am unable to pass the value of data-href to the button inside the modal. Upon clicking the button, nothing happens. Seeking assistance to resolve this ...

Creating a continuous loop in JQuery when clicking on a table row

I seem to be encountering an issue with what appears to be an infinite loop. My problem arises while trying to create a table dynamically using Ajax. Each row of the table contains a button alongside a thumbnail image and some text. I wish for the button ...

Utilize data from a dynamically loaded component within a parent component in Vue.js

In my Vuejs application, I've implemented a wizard-type flow with dynamically loaded components. The parent component contains the Save button, while the child components have all the text fields. Upon clicking the Save button, I need to achieve two m ...

In Bootstrap 5, clicking inside a dropdown should not cause it to open or close unexpectedly

Check out the code snippet below: <html> <head> <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7d1f1212090e090f1c0d3d48534e534e">[email protected]</a>/d ...

What is the method for bringing in Mongoose to utilize json.parse()?

I'm really eager to utilize this code for importing a JSON file into JavaScript var treeData; var oReq = new XMLHttpRequest(); oReq.onload = reqListener; oReq.open("get", "test.json", true); oReq.send(); function reqListener(e) { treeData = JSON. ...

How can a button be linked directly to a particular list item?

I currently have a HTML tag within my React application that looks something like this: <ul> <li> Item 1 <button> Delete </button> </li> <li> Item 2 <button> ...

Error 403 with Firefox on Font Loading for CodeIgniter Website

Utilizing font-face in CSS to integrate custom fonts onto a web application being developed with CodeIgniter. This is the CSS code: @font-face { font-family: 'UniversLT-UltraCondensed'; src: url('../Fonts/LTUnivers/universlt59ultrac ...