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

Leverage the power of React in tandem with Express

My web site is being created using the Express framework on NodeJS (hosted on Heroku) and I'm utilizing the React framework to build my components. In my project, I have multiple HTML files containing div elements along with React components that can ...

Styling the topbar with CSS includes adding a vertical separator that neatly wraps the content within the

I recently created a website using HTML and CSS, featuring a topbar. However, I encountered an issue while trying to insert a vertical separator between some of the icons within the topbar. Initially, when I added the separator-div, only the first three ic ...

Issue "Invalid UTF-8" encountered while compiling sass using @import

Here is the structure of my project: project assets scripts styles app.scss bower_components node_modules public css app.css js bower.json gulpfile.js package.json I am using gulp-sass to compile app.scss into ap ...

What methods can be used to stop HTML5 audio from pre-downloading or streaming upon loading?

I am experiencing slow load times on my single page website that features a variety of HTML5 audio players. The issue seems to stem from certain browsers predownloading the content (mp3 and ogg). Internet Explorer Google Chrome Firefox Safari (probably Op ...

Improving Java Performance by frequently replacing one String with another

Currently, I am developing an HttpServlet extension (plugin) for a CMS that is responsible for filtering the HTML response. Within my method filterResponse, I retrieve the requested text/html as a String, which is one of three parameters. The main task a ...

Tips on obtaining the data count from using the $.get method

Here is the code I'm currently working with: $.get('getstatsAccepted' + tickerid, {tickerid: tickerid}, function(data) { alert(data.length); }, 'json'); I am interested in obtaining the numbe ...

Creating a hexagonal grid pattern with the use of texture

I have conducted several experiments in the past to determine the most effective way to create large-scale hexagon grids. I attempted drawing the hexagons using THREE.Line and THREE.LineSegments. While this method was successful for small grids, the perfo ...

Variables for Angular Material themes

My app has multiple theme files, and I select the theme during runtime. .client1-theme{ // @include angular-material-theme($client1-theme); @include all-component-colors($client1-theme); @include theme-color-grabber($client1-theme, $client1-a ...

Footer that is adhered to the bottom of the page with a

Can a sticky footer with a transparent background be achieved without a content background (.wrapper) underneath it? I found this resource: ...

Hinting the type for the puppeteer page

I am trying to type hint a page variable as a function parameter, but I encountered a compilation error. sync function than_func(page:Page) ^ SyntaxError: Unexpected token: ...

Issue with Many to Many Relation Query in Objection JS, Postgres, and Express Resulting in 'TypeError: Cannot Read Property 'isPartial' of Null' Error

I have a challenge connecting the 'products' table to the 'tags' table using a many-to-many relationship structure with the 'products_tags' table. Upon executing const product = await Product.relatedQuery('tags').fi ...

Rewriting URLs in Angular 2

I am a beginner in Angular 2 and I am currently working on a project that requires URL rewriting similar to that of ' '. In Zomato, when you select a city, the city name appears in the URL like ' ', and when you select a restaurant, t ...

Using services in Angular 6 CLI with dynamically added components

One of my recent projects involved creating a directive in Angular 6 called 'DeleteDirective' and integrating it with a service called 'DeleteService' to enable the deletion of items from the application. Once an item is deleted (handle ...

How to ensure the height of an image in a Bootstrap flex row matches the

I just updated to the latest Bootstrap 5.0 beta version and I'm working with this html code snippet: <div> <div class="d-flex flex-row"> <img src="img/funny.png" alt=""> ...

Guidelines on populating a Vue array with data fetched from an Axios request

The v-breadcrumbs component is used to display data from the breadcrumbs array, which works seamlessly with static data. <v-row> <!-- Breadcrumbs --> <v-col class="d-flex"> <v-breadcrumbs :items="breadcrumbs"></v ...

Issue with React submit button for posting data is not functioning as intended

My dilemma lies within a Modal component containing a Form and Button. The goal is to trigger a POST request (managed in a separate file) upon the user clicking the button, which will run a simulation using the validated input values. Surprisingly, the onC ...

Collaborative JavaScript repository within the Websphere Liberty platform

Is it possible to utilize a JavaScript library (such as Dojo, JQuery, or other custom developed libraries) as shared libraries within a Websphere Liberty server? For instance, I am interested in storing the .js files in either C:\wlp\usr\sh ...

The process of integrating a Loader in Javascript

I am in need of a simple "page loading" animation while my photo is being uploaded. Unfortunately, when I tried using the "blockUI" JavaScript for this purpose, it didn't seem to work with my form. For uploading the image, I have employed a div as a ...

Retrieve content from inner tag using Selenium

Check out this snippet of HTML code: <label class="abc"> <span class="bcd">Text1</span> Text2 </label> Is there a more efficient method to extract only Text2 using a selenium script? I currently extract Text2 by accessing the ...

Mongoose fails to carry out internal query using Promise mechanism

Just diving into the asynchronous and await world, I decided to play around with Mongoose + MongoDB + Node.JS. Here is a snippet of my code: exports.updateBrandPreferences = async (req,res) => { var userID = req.body.playerID; var newBrands = r ...