Develop a distinctive JavaScript solution that enables an image to appear in fullscreen upon loading the page, and then smoothly fade away after precisely

I have been trying to incorporate a feature on my Shopify frontage website where our logo appears fullscreen and then fades away or disappears after a few seconds, allowing people to access the rest of the website. However, I am facing difficulty in making these two parts of HTML work together.

If anyone can provide assistance with this issue, it would be greatly appreciated.

Thank you!

<div id="makethisvanish"><img src="image"></div> 

     <div class="fixed-background">
            <img src="image" class="myimg">
        </div>



    <script type="text/javascript"> 
    window.onload = function () { 
    window.setTimeout( vanishText, 2000 ); // 2000 is 2 seconds 
    } 
    function vanishText() { 
    document.getElementById( 'makethisvanish' ).style.visibility = 'hidden'; 
    } 
    </script>


    <style>
    body {
        height: 100%;
        width: 100%;
        margin: 0;
        padding: 0;
    }

    .fixed-background {
        position: absolute;
        top: 0;
        left: 0;
        height: 100%;
        width: 100%;
        overflow: hidden;
    }

    .myimg {
        height: inherit;
    }
    </style>

Answer №1

Here's a code snippet you can try:

<head>
  <script>
    window.onload = function () { 
      window.setTimeout(disappearText,2000); // wait for 2 seconds before disappearing
    } 
    function disappearText() { 
      document.getElementById('fadeaway').style.opacity = '0';
    }
  </script>
  
  <style>
    body {
      height: 100%;
      width: 100%;
      margin: 0;
      padding: 0;
    }

    #fadeaway {
      display: block;
      position: fixed;
      top: 0;
      left: 0;
      width: 100%;
      min-height: 100%;
      height: auto;
      opacity: 1;
      z-index:1000;
      margin: 0 auto;
      transition: opacity .5s linear;
    }

    #fadeaway img {
      width: 100%;
      height: auto;
    }

    .full-background {
      position: relative;
      top: 0;
      left: 0;
      height: 100%;
      overflow: hidden;
    }

    .grid__item {
      height: 50px;
    }

    .myimage {
      height: 100%;
      width: auto;
    }
  </style>
</head>
<body>

  <div id="fadeaway">
    <img src="http://i65.tinypic.com/5nn1va.jpg">
  </div>

  <div class="grid__item">
    <div class="full-background">
      <img src="http://i65.tinypic.com/5nn1va.jpg" class="myimage">
    </div>
  </div>
</body>

I believe this solution should work for you.

Let me know if you encounter any issues. I'll be happy to assist you in resolving them :)

Disclaimer: This code snippet has been customized for your specific requirements and usage may vary depending on your website's structure and other factors. It is recommended to test the code thoroughly before implementing it on a live site.

Update:

If you only want the full-screen picture to vanish, you can use even less code:

<head>
  <script>
    window.onload = function () { 
      window.setTimeout(disappearText,2000); // wait for 2 seconds before disappearing
    } 
    function disappearText() { 
      document.getElementById('fadeaway').style.opacity = '0';
    }
  </script>

  <style>

    #fadeaway {
      display: block;
      position: fixed;
      top: 0;
      left: 0;
      width: 100%;
      min-height: 100%;
      height: auto;
      opacity: 1;
      z-index:1000;
      margin: 0 auto;
      transition: opacity .5s linear;
    }

    #fadeaway img {
      width: 100%;
      height: auto;
    }

  </style>
</head>
<body>

  <div id="fadeaway">
    <img src="http://i65.tinypic.com/5nn1va.jpg">
  </div>

</body>

You may need to add another line in the `disappearText()` function:

document.getElementById('fadeaway').style.zIndex = "0";

However, try using the code above first.

Update_2:

To replace the script in the head section with the following:

window.onload = function () {
  window.setTimeout(disappearText,2000); // wait for 2 seconds before disappearing
}

var IDLE_TIMEOUT = 60; //seconds
var _idleSecondsCounter = 0;

window.setInterval(CheckIdleTime, 1000);

function CheckIdleTime() {
  _idleSecondsCounter++;
  if (_idleSecondsCounter >= IDLE_TIMEOUT) {
    screensaver();
  }
}

function disappearText() { 
  document.getElementById('fadeaway').style.opacity = '0';
  document.getElementById('fadeaway').style.zIndex = '-1';
}

function screensaver() {
  document.getElementById('fadeaway').style.zIndex = "1000";
  document.getElementById('fadeaway').style.opacity = "1";
}


function resetTimer() {
  if(_idleSecondsCounter >= IDLE_TIMEOUT) {
    disappearText();
  }
  _idleSecondsCounter = 0;
}

document.onclick = function() {
  resetTimer();
};

document.onmousemove = function() {
  resetTimer();
};

document.onkeypress = function() {
  resetTimer();
};

You'll probably need to adjust the `IDLE_TIMEOUT` value. It's currently set to 5 seconds for testing purposes. I recommend setting it to one minute or more. The "screensaver" should disappear if the mouse is moved, a mouse click occurs, or a key on the keyboard is pressed.

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

Having issues with utilizing $fetchState in Nuxt 2.12

Recently, I've been exploring the new functionality outlined in the documentation. However, I'm encountering an error that states : Property or method "$fetchState" is not defined on the instance but referenced during render. Despite clearly ...

Ways to interact with a button that toggles between states

I am working with a button that has both an enabled and disabled state. Enabled State: <button type="button" class="btt-download-csv site-toolbar-menu-button icon-download no-icon-margins ng-isolate-scope" title="Download CSV" rc-download-csv="" curren ...

Necessary Quasar Select Dropdown Class

Looking to set an asterisk (*) next to the Select component in Quasar when it is marked as "required". While I can achieve this with the input component, replicating the same behavior for dropdowns has proved challenging. I attempted using the :deep selec ...

Node(Meteor) experiencing a memory leak due to setTimeout

I have encountered an unusual memory leak associated with the use of setTimeout. Every 15 seconds, I execute the following code using an async function that returns an array of promises (Promise.all). The code is supposed to run again 15 seconds after all ...

Utilize PHP to transform JSON data into JavaScript

Hello, I am a newcomer to Stackoverflow and I need some assistance. My issue involves converting JSON with PHP to JavaScript. I am using PHP to fetch data from a database and create JSON, which I then want to convert for use in JavaScript as an object (obj ...

In internet explorer with AJAX, the UI is refreshed by Javascript only when an alert() function is triggered

Having an issue in Internet Explorer, works perfectly in Firefox. There is a javascript function that updates the UI (screen content) before an AJAX call. However, it does not update the UI unless an alert box prompt is used. Without the alert box, the UI ...

Issues with hidden overflow and height attributes not functioning correctly in Internet Explorer 9 when using the DOCTYPE HTML standards mode

I have a <div> with overflow:hidden and height:100% that adjusts the div contents to fit the window's height on Chrome and Safari. However, in IE9, the div does not respect the styles of overflow:hidden and height:100%, causing it to expand to ...

How to efficiently transfer data between Node and Angular 7 using Electron

After setting up an Angular 7 application running on http://localhost:4200, I developed a Node JS application responsible for authenticating users on Facebook, accessible at http://localhost:3000. The callback redirection functions correctly within the No ...

Halt the execution of a function upon clicking a div element

I'm currently working on a function that needs to be stopped when a div with the class "ego" is clicked. This function toggles the visibility of the header based on the scroll position and should only run by default. Below is the code snippet: $("#e ...

Utilizing jQuery to Trigger a JavaScript Function in a Separate File

Here is my question: I currently have 2 files: //File1.js function TaskA() { //do something here } //File2.js function TaskB() { //do something here } $(function() { TaskA(); }); The issue I am facing is that the TaskB function in File2.js ...

Arrow function returns itself, not the function

While working with React, I've been using utility functions for managing API calls. I noticed that when the arrow function is no longer anonymous, it successfully returns a pending promise – which is exactly what I want. However, if the arrow functi ...

Ways to retrieve the output parameter in the node mssql

` request.input('xyz',sql.Int,1); request.input('abc',sql.Numeric,2); request.output('pqr',sql.Int); request.output('def',sql.Char); request.execute('[StoredProcedure]',function(err,recor ...

Guide on running a MySQL query in an asynchronous function in a Node.js application

Encountering some challenges while using MySQL in a node/express JS application. It seems that when trying to access the MySQL database within an asynchronous function, the code will 'skip over' the SQL query and run synchronously. This is the co ...

Having trouble with margins not working after adding the clear property in CSS?

I recently applied clear:left to a div in my code, but when I tried adjusting the top margin, nothing seemed to change. Take a look at the snippet below: <!DOCTYPE html> <html> <head> <title>Float</title> <meta cha ...

What could be causing the issue with the 100% height and 100% width not functioning properly on my ASPX page?

The CSS and HTML code work perfectly in an isolated test environment: body, html { height: 100%; min-height:600px; min-width:800px; overflow:hidden; margin:0;padding:0; } html {overflow:auto;} .fill {height:100%; width:100%; backgro ...

`Positioning of inline-block elements`

I am encountering an issue with the display CSS attributes set for three tags: a - inline-block img - block span - inline <a id="first"> <img/> <span> A first line of text B second line of text </span> </a> <a id="secon ...

I'm curious if there is an eslint rule specifically designed to identify and flag any unnecessary spaces between a block comment and the function or

Can anyone help me find a solution to prevent the following issue: /** * This is a comment */ function foo() { ... } I need it to be corrected and formatted like this: /** * This is a comment */ function foo() { ... } ...

Can config values be dynamically set from an Excel file in Protractor?

I am currently working on parameterizing capabilities using an Excel sheet. For this task, I am utilizing the npm exceljs package for both reading and writing data. Below is a snippet of the code that demonstrates how I am trying to achieve this: //This f ...

What is the reasoning behind CoffeeScript automatically adding a function when extending an Object?

I'm currently working on a helper method to identify the intersection of two hashes/Objects in this manner... Object::intersect = (obj)-> t = {} t[k] = @[k] for k of obj t x = { a: 1, b: 2, c: 3 } w = { a: true, b: 3 } x.intersect(w) #=> ...

`Can Beautiful Soup extract data (text) from elements that share the same class identifier?`

Currently working on a personal project focused on web scraping, using beautiful soup to extract data from a website. Encountered an issue where data with the same class but different attributes is present. For instance: <div class="pi--secondary-price ...