jQuery - Enhancing User Experience with Dynamic Screen Updates

Is there a way to update the screen height when resizing or zooming the screen? Whenever I zoom the screen, the arrows break.

I'm also curious if the method I'm using to display images on the screen is effective. It's supposed to be a parallax website where scrolling down changes the content with a sharp (#) and scrolls to new content below. However, the transition when clicking the arrow isn't smooth, it simply changes abruptly, which seems like an issue...

This is the code I currently have:

/* Resize to fit screen */
window.onload = function() {
    var height = getViewportHeight();
    document.getElementById("main").style.height = height + "px";
    document.getElementById("lobby").style.height = height + "px";
}

function getViewportHeight() {
    var h = 0;
    if(self.innerHeight)
        h = window.innerHeight;
    else if(document.documentElement && document.documentElement.clientHeight)
        h = document.documentElement.clientHeight;
    else if(document.body) 
        h = document.body.clientHeight;
    return h;
}

HTML:

<!DOCTYPE html>
<html lang="cs">
    <head>
        <title>Zahrajem.cz | Nový československý herní portál</title>
        <meta charset="utf-8">
        <meta name="author" content="Jan Dvořák">
        <meta name="description" content="Zahrajem.cz | Nový český herní portál">
        <meta name="version" content="1.0">
        <link rel="stylesheet" href="css/style.css">
        <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:400,300,400italic,600,700">
        <script src="http://code.jquery.com/jquery-2.2.2.min.js"></script>
        <script src="main.js"></script>
    </head>
    <body>
        <section id="main">
            <div class="container">
                <div class="header">
                    <img src="img/z_logo.png"/>
                </div>

                <div class="footer">
                    <a href="#lobby"><img src="img/z_down.png"/></a>
                </div>
            </div>
        </section>

        <section id="lobby">
            <div class="container">
                <div class="header">
                    <a href="#main"><img src="img/z_up.png"/></a>
                </div>          
            </div>
        </section>
    </body>
</html>

CSS:

html, body {
    font-family: "Open Sans", "sans-serif";
}

* {
    padding: 0;
    margin: 0;
}

/* ANIMATION */
@-webkit-keyframes pulsate {
    0% {-webkit-transform: scale(0.92, 0.92);}
    100% {-webkit-transform: scale(1.0, 1.0);}
}
@-moz-keyframes pulsate {
    0% {-webkit-transform: scale(0.92, 0.92);}
    100% {-webkit-transform: scale(1.0, 1.0);}
}
@keyframes pulsate {
    0% {-webkit-transform: scale(0.92, 0.92);}
    100% {-webkit-transform: scale(1.0, 1.0);}
}

@-webkit-keyframes arr {
    0% {opacity: 0.4;}
    100% {opacity: 1.0;}
}
@-moz-keyframes arr {
    0% {opacity: 0.4;}
    100% {opacity: 1.0;}
}
@keyframes arr {
    0% {opacity: 0.4;}
    100% {opacity: 1.0;}
}

/* STRUCTURE */

#main {
    overflow: auto;
    background-image: url('/img/z_background.jpg');
    background-repeat: no-repeat;
    background-attachment: fixed;
    background-size: cover;
    display: block;
}

#main .container {
    margin: auto;
    text-align: center;
}

#main .container .header {
    margin-top: 10%;
}

#main .container .header img {
    -webkit-animation: pulsate 2s ease-in-out infinite alternate;
    -moz-animation: pulsate 2s ease-in-out infinite alternate;
    animation: pulsate 2s ease-in-out infinite alternate;
}

#main .container .footer {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
}

#main .container .footer img {
    width: 50px;
    height: 50px;
    opacity: 0.4;
}

#main .container .footer img:hover {
    -webkit-animation: arr 0.7s ease-out infinite alternate;
    -moz-animation: arr 0.7s ease-out infinite alternate;
    animation: arr 0.7s ease-out infinite alternate;
}
  
/* LOBBY */

#lobby {
    overflow: auto;
    background-image: url('/img/z_lobby_bg.jpg');
    background-repeat: no-repeat;
    background-attachment: fixed;
    background-size: cover;
    display: block;
}

#lobby .container {
    margin: auto;
    text-align: center;
}

#lobby .container .header {
    position: absolute;
    left: 0;
    right: 0;
}

#lobby .container .header img {
    width: 50px;
    height: 50px;
    opacity: 0.4;
}

#lobby .container .header img:hover {
    -webkit-animation: arr 0.7s ease-out infinite alternate;
    -moz-animation: arr 0.7s ease-out infinite alternate;
    animation: arr 0.7s ease-out infinite alternate;
}

If you notice any errors in my current code, please feel free to correct them. I appreciate any help you can provide to improve my code.

Check out the preview here:

Answer №1

Similar to the onload event, we also have an event called onresize:

window.onresize = function(event) {
    var windowHeight = getViewportHeight();
    document.getElementById("main").style.height = windowHeight + "px";
    document.getElementById("lobby").style.height = windowHeight + "px";
};

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

struggling to implement captcha verification with jQuery validation

I've been working on real-time captcha validation using jQuery Validation version 1.11.1. The captcha value is stored in a session variable called security_code. I'm utilizing the remote method of jQuery for this purpose, which is my first time u ...

Input fields that are dynamically generated do not respond to changes made using .click and .blur methods in jQuery CSS

I'm experiencing an issue with a HTML form where a new input field is generated when a button is clicked, but the dynamically created field is not styled properly. Below is the HTML form code: <form id="form"> <input type="text" id="ent ...

What is the best way to utilize the sx prop in Material UI for applying styles specifically when the component is active or selected?

In the code snippet below, I have set up the useState hook so that when a ListItem is clicked on, the selected state becomes true. My goal is to apply specific styling when an item is selected using the sx prop instead of creating a styled component for su ...

The Angular ng-repeat directive is populating a list with items, but the parameters enclosed in double curly braces

After calling an API, the response contains data in the following format: [{name: "ABC", age: 20}, {name: "DEF", age: 25}] Even though the $scope.names variable is assigned with the array from the API, when viewed in the browser, it displays 2 rows but th ...

Adjust the vertical alignment in Material UI Grid to allow for proper tab navigation while maintaining the original order

When using Material-UI's standard grid system, the alignment of a new grid item after all 12 "space units" are utilized is based on the longest element within those 12 "space units". Is there a way to disrupt this type of alignment? If you take a look ...

Is there a way to emulate synchronous behavior in JavaScript?

var routeSearch = new MyGlobal.findRoutes({ originPlaceId: search.placeInputIds.originPlaceId, destinationPlaceId: search.placeInputIds.destinationPlaceId, directionsService: search.directionsService, directionsDisplay: sear ...

What is the method for deactivating a form input field in Angular Formly?

Is there a specific way to disable a form input field using Angular Formly? I have tried searching online and cannot find a clear answer. Even after checking Formly's 'field configuration docs', I only found one mention of the word 'dis ...

Utilizing ng-model to control the visibility of a label or anchor tag

Here is the code snippet I am working with: <div class="tabs DeliveryRightDiv"> <label class="selected"><a>One</a></label> <label> <a>Two</a> </label> <label> ...

What is the method of adding a child to the outerHTML of the parent element instead of within it?

Is there a way to use the outerHTML method on a parent element to append a child element so that the icons appear outside of the targeted element rather than inside it? The current code snippet shows the icons inside the box, but I want them to be placed o ...

Is OpenLayers + Ajax causing issues or errors?

Utilizing the code provided below to showcase an OpenLayers map within a DIV container presents a peculiar issue. Upon initial load of the webpage, the map does not display consistently - requiring multiple page refreshes in order for it to become visible. ...

Using CSS absolute/relative positioning in a flyout menu: Utilizing specific parent properties (such as left, top, width, vertical/horizontal alignment) while disregarding others

I recently encountered a common issue in CSS involving flyout menus with sub-menus that are shown on hover. When attempting to position the sub-menu directly below the parent list item, I used position:relative; on the parent item and position:absolute;top ...

The Material-UI DataGrid feature allows for the display of column sums, with the sum dynamically updating based on applied filters

I am struggling with calculating the sum of values in the Total Amount column of my Material-UI DataGrid. How can I achieve this and ensure that the sum is also updated when a filter is triggered? Any guidance on how to sum the entire Total Amount column ...

What is the process for setting up a redirect to the login page in ASP.NET?

When using ASP.NET, what is the most effective method for redirecting a user to the login page if they try to access a page intended for registered users? Please note that although I am utilizing ASP.NET WebForms, there are no actual WebForms involved. Th ...

What is the best way to identify the position of an element in an array given my specific circumstances

I am trying to utilize the ng-repeat directive in order to display an array. Here is what I have: <div ng-repeat="stu in school"> <div>{{stu.name}}</div> <div>{{stu.grade}}</div> </div> JavaScript $scope.scho ...

What types of numerical values is the Number data type capable of storing?

Is it true that a JavaScript number has the ability to store both a 64-bit number and a 64-bit Integer? I'm still unsure about this concept. ...

Is it possible to eliminate the background color by double clicking on a row within an HTML table?

I am currently working on an HTML table with jQuery functionality that allows for highlighting a row when selected, and double-clicking to remove the highlight. Additionally, I would like to ensure that only one row is selected at a time. The code below s ...

Problem with jQuery image gallery

Currently, I am in the process of creating a simple image gallery that enlarges an image when it is clicked. To achieve this functionality, I am utilizing jQuery to add and remove classes dynamically. $(".image").click(function() { $(this).addClass("b ...

How can you access the preloaded resolve value in AngularJS ui-router when the $stateChangeSuccess event is triggered?

$stateProvider.state('home', { url: '/', resolve: { person: function() { return 'good' } } Can you help me figure out how to access the value of 'person' in the $stateChangeSuccess callback f ...

How can React useEffects avoid an infinite loop when using setData()?

const [resourceType, setResourceType] = useState("posts"); const [data, setData] = useState(""); useEffect(() => { console.log("use effects called: " + resourceType); fetch(`https://jsonplaceholder.typicode.com/${resourceType}`) .then((result ...

Refresh the PHP MySQL table view based on selection changes in the dropdown menu

Hello there! I currently have a table displayed on my page thanks to the following code: $result = mysql_query("Select * from porders, porders_detail, parts where porders.order_no = porders_detail.order_no and porders_detail.om_part_no = parts.om_part_no" ...