Blurring a backdrop using jQuery

I need assistance with fading a background image every 2 seconds without changing the whole document. I have been struggling to accomplish this task on my own for the past few days as I am not very skilled in JavaScript or jQuery.

If anyone could provide any guidance or help, it would be greatly appreciated. Below is the code that I have been working on:

index.html

<!DOCTYPE html>
            <html>

            <head>
                <title>Buddies Server Home</title>
                <link href="css/styles.css" rel="stylesheet" />
                <script src="http://code.jquery.com/jquery-latest.js"></script>
            </head>

            <body>
                <div class="body">
                    <div class="nav">
                        <div class="header">
                            <img src="images/Logo.png" />
                        </div>
                        <div class="right-side">
                            <img src="images/home.png" />
                        </div>
                        <div class="nav-buttons">
                            <a href="http://192.168.2.202/server"><img src="images/buttons/servers.png" /></a>
                            <a href="about.php"><img src="images/buttons/about.png" /></a>
                            <a href="/forum/index.php"><img src="images/buttons/forums.png" /></a>
                        </div>
                        <div class="notif_container">
                            <div class="notif"><p id="notif">NOTIFICATION: Buddies Network is under maintenance. Thank you for your patience.</p></div>
                        </div>
                    </div>
                </div>

                <div class="content">
                    <div class="post">
                        <table id="post">
                            <tr>
                                <td id="title"><h2>Blog Entry 1</h2></td>
                            </tr>
                            <tr>
                                <td><h5 id="author">DirectX3DNerd, 7/23/13</b></td>
                            </tr>
                            <tr>
                                <td id="body"><p>Post Body</p></td>
                            </tr>
                        </table>

                        <table id="post">
                            <tr>
                                <td id="title"><h2>Blog Entry 2</h2></td>
                            </tr>
                            <tr>
                                <td><h5 id="author">DirectX3DNerd, 7/1337/13</b></td>
                            </tr>
                            <tr>
                                <td id="body"><p>Post Body - Jacob was Here</p></td>
                            </tr>
                        </table>
                    </div>

                    <div class="side_bar">
                        <table id="side_bar">
                            <tr>
                                <td><h2>Welcome!</h2></td>
                            </tr>
                            <tr>
                                <td><p>Welcome to Buddies Netowrk! Home of the Minecraft, Ace of Spades, and Team Fortress 2 server! If you want to play on one of the servers, click <a href="servers.php">here</a></p></td>
                            </tr>   
                        </table>
                    </div>
                </div>
                <div class="footer">
                    <b>&copy; Buddies Network, 2012-2014.</b>
                </div>
            </body>
            <script>
              var image1 = 'images/bg.png';
              var image2 = 'images/bg2.png';

            function fade() {
                $(html).css('background-image', image1);
                $(html).css('background-image', image1);
            }
            </script>

            </html>

styles.css

/* Document Properties */
            html {
              background: url('../images/bg.png') no-repeat center center fixed; 
              -webkit-background-size: cover;
              -moz-background-size: cover;
              -o-background-size: cover;
              background-size: cover;
            }

            /* Server List Properties */
            .server_list {
                width:500px;
                height:400px;
                margin: auto;
            }
            .server_list li {
                width:60%;
                margin:auto;
            }

            /* Font Properties */
            b{
                font-family:"Times New Roman", Times, serif;
            }
            h1{
                font-family:"Times New Roman", Times, serif;
            }
            p{
                font-family:"Times New Roman", Times, serif;
            }

            /* Page Template */

            /* Navigation Bar*/
            .header {
                position:relative;

                left:-1px;
            }

            .right-side {
                position:absolute;
                left:850px;
                top:1px;
            }
            .notif {
                background-color:#00FF15;

                position:relative;
                top:4px;
            }

            #notif {
                color:#000000;

                font-family:"Lucida Console", Monaco, monospace;
                /*font-size:79%;*/

                width:800px;
                height:35px;

                margin:auto;

                position:relative;

                top:10px;

                overflow:auto;
                word-wrap:break-word;
            }

            .nav {
                background-color:#FFFFFF;

                min-height:79px;
                min-width:100%;

                position:fixed;

                top:0px;
                left:0px;
                right:0px;

            }

            /* Footer */
            .footer {
                background-color:#eee;

                min-width:100%;
                height:20px;

                position:fixed;

                left:0px;
                bottom:0px;
            }

            /* Blog Post styles */
             .post {
                background-image:url('../images/trans_bg.png');

                color:white;
                position:absolute;
                z-index:-1;
                top:200px;
                left:350px;

                width:550px;
                height:750px;
            }

            #post {
                position:relative;
                left:0px;

                padding:0;
                margin:0;
            }

            #title {
                position:relative;

                top:-10px;
                left:0px;
            }

            #author {
                position:relative;
                top:-50px;
                left:0px;
            }

            #body {
                position:relative;
                top:-80px;
                left:0px;
            }

            /* Misc */
            .side_bar {
                background-image:url('../images/trans_bg.png');
                color:white;

                position:fixed;
                top:190px;
                left:5px;

                width:250px;

                word-wrap:break-word;
                overflow:hidden;
            }

            /* link Properties */
            a:link { color:white; }
            a:visited { color:white; }
            a:hover { color:white; }
            a:active { color:white; }

Answer №1

Include this snippet of code in your project:

jQuery(document).ready(function() {

 $("html").css({
'background-image': ''
 });

$("html").animate({ background:'url(image.png)'},350); 

});

This code snippet will create a fade effect for the first image on your website. If you want to apply this effect to multiple images, consider using this helpful plug-in for a more streamlined process and visually appealing results.

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

Is it possible to apply a modal to a v-for item?

I am receiving a GET request from my API to display all users, and I want to potentially modify the name or email of each user using a modal. However, I am facing an issue where if I have 3 users displayed, clicking on one modal button triggers all 3 modal ...

differences in the way web pages are displayed in Microsoft Edge and Internet Explorer when compared to

I can't wrap my head around the issue I'm currently facing: it seems that MS Edge and Internet Explorer display things at a similar size to other browsers only when the user's zoom level is set to 150% (not 100%). Am I the only one experien ...

What is the best way to vertically center the `tab-content` without relying on the tablist for

After examining the form below, my goal is to center only the fields while keeping the navigation buttons in their original position. Specifically, I want only the tab-content to be centered, excluding the tablists. <link rel="stylesheet" href="https ...

`How can you utilize typeahead.js to showcase images on your webpage?`

Is there a way to show images using typeahead.js? I am attempting to include profile images in the list generated by typehead.js. Currently, I can only display text in the list as shown below: This is how my javascript appears: Along with my PHP code w ...

Illustrative Python Django email submission form demo

I am currently working on creating a contact form for my website, but I am struggling to find examples using Django. While PHP email forms are readily available, I don't have the knowledge to create one from scratch using Django. Is there anyone who c ...

Choose All / Deselect All Toggle for Checkbox Arrays Using the Name[] Naming Standard

I have a dynamic form with multiple sets of checkboxes that are initially checked by default. Upon form submission, arrays are created in the $_POST based on the checked checkboxes. The entire form is generated dynamically using PHP and data from a databas ...

Leveraging jQuery to manipulate an SVG file

jQuery is designed to work within HTML pages that contain JavaScript code. While SVG and HTML both use the same DOM Level 2, SVG is XML-based and employs ECMAScript. What potential issues could arise from utilizing jQuery with SVG? Is it more advisable t ...

I am facing difficulties installing packages such as react-bootstrap on my dashboard

Encountering an issue with installing packages in my dashboard. For example, attempting to install react-bootstrap results in the following error: node version: 12.16.1 npm version: 6.13.4 gyp ERR! UNCAUGHT EXCEPTION gyp ERR! stack Error: Cannot find mo ...

I can't seem to locate the datepicker in Material UI Next. Can you point

I'm attempting to use the next branch of Material UI from https://github.com/callemall/material-ui/tree/next. I need to utilize the layout component, but it seems that the DatePicker component is missing. How can I include the DatePicker in the next b ...

Is there a way to intercept and control mousewheel scrolling before it occurs?

I am in search of a way to intercept the event triggered by a mousewheel scroll right before it occurs, in order to prevent the scroll action, execute certain tasks, and then allow the user to regain control. Currently, I have the following code set up to ...

Learn how to verify the existence of a URL or webpage using AJAX or jQuery

When a user is creating a profile, they have the option to include links to their websites or blogs that will be displayed on their profile page. Before saving these links to the database, I would like to verify if the provided URL exists. Is there a meth ...

Attempting to integrate a chatroom name entered by the user using a combination of Ajax and Python

Despite reading numerous textbooks on computer science, I have been struggling with sending ajax form data to Python and checking it in a dictionary before parsing it into a JSON object. The concept of dictionaries with key-value pairs is clear; however, a ...

Tips for optimizing the performance of nested for loops

I wrote a for loop that iterates over 2 enums, sending them both to the server, receiving a value in return, and then calculating another value using a nested for loop. I believe there is room for improvement in this code snippet: const paths = []; for awa ...

Develop an asynchronous function that can fetch a result at a later time within an Express route

I need to retrieve an Excel file from Box.com using their API and then convert the Excel data into JSON format. Afterwards, I plan to display this JSON data using Express and Handlebars. Below is the function I've created for fetching the Excel file ...

Enable the duplication of strings within an array

Below is the HTML code snippet I am working with: <div class="col-sm-8"> <div class="row col-sm-12 pull-right paddingDiv"> <div class="col-sm-12"> <div class="marginBottom pull-right"> <bu ...

Align text within HTML with the use of Bootstrap

Example data value category type item1 100 food fruit item2 50 drinks soda item3 75 snacks chips I want to achieve this forma ...

Using C# Selenium WebDriver to interact with JavaScriptExecutor for handling prompt windows

I am faced with a JavaScript Prompt Window that I need to handle. Previously, I was able to manage a simple prompt with only an 'OK' and 'Cancel' button using the following code: ((IJavaScriptExecutor)ts.getDriver()).ExecuteScript("win ...

What is the best way to transfer a PHP variable to a separate PHP page based on its object ID for additional processing?

Currently, I am utilizing a PHP-generated link/button to transfer a variable to the destination page and then using $_GET[''] to retrieve this variable. The anchor tag script looks like this: echo "<a href='miniStat.php?pod=<?php echo ...

What is the process for loading an external file within an npm script?

Objective: Testing the linting process of specific components within the source code, without affecting all files. I want to streamline the linting process by running a single command that covers multiple folders specified in a configuration file: //pack ...

The <transition> element is not being recognized by VSCode

It seems like my VSCode is highlighting the transition element in red, indicating that it may not be recognizing this element. I'm a bit perplexed by what's happening here. Moreover, the code isn't functioning as expected because there is no ...