Cover the whole page in darkness and emphasize the division element

I attempted to implement a solution I found on stackoverflow without success. The issue is that the blackout feature does not seem to activate - nothing happens.

Within my JavaScript code (all enclosed in the $(document).ready(function () tag), it appears like this:

// Display MicroClean Details window
$(function () {
    $("#MicroCleanClick").click(function () {
        $("#GraphBox").show();
        $(this).css("z-index","99999");
        $("#overlay").fadeIn(300);
        loadGraph();
        return false;
    });
});

// Remove blackout
$("#overlay").click(function (e) {
    $("#overlay").fadeOut(300, function () {
        $(".expose").css("z-index", "1");
    });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a id="MicroCleanClick" href="#" class="button">Show Data</a>
               
<div class="expose" id="GraphBox">

    <p class="checkbox"><input type="checkbox" name="temperature" value="temp"> Temperature <input type="checkbox" name="relHumidity" value="relhum"> Rel. Humidity</p>
    <p class="datepicker">From: <input type="text" id="fromDate"> To: <input type="text" id="toDate" ></p>

    <canvas id="myChart" width=800 height="450"></canvas>
    <div id="legendDiv"></div><br>
</div>

UPDATE:

Here is the CSS styling for #overlay and .expose:

.expose {
    position:relative;

}

#overlay {
    background:rgba(0,0,0,0.3);
    display:none;
    width:100%; height:100%;
    position:absolute; 
    top:0; 
    left:0; 
    z-index:99998;
}

Answer №1

One issue that stands out is the absence of a <div id='overlay'> element which requires the following styling:

#overlay {
    position: absolute;
    top: 0;
    bottom: 0;
    right: 0;
    left: 0;
    background-color: black;
    display: none;
    z-index: 1;
}

Once you incorporate this and style it accordingly, everything should function properly. Take a look at this jsfiddle link for an illustration. However, it's not crystal clear from the provided information about the specific content to display when the black overlay appears.

Furthermore, keep in mind that fadeIn() and fadeOut() animate the display property, so any element targeted by fadeIn() should initially have display: none;

Link to the mentioned jsfiddle: https://jsfiddle.net/hxq4nd6g/

Answer №2

Make sure to update the line $(this).css("z-index","99999"); with

$("#GraphBox").css("z-index", "99999");
as the element that needs to remain on top of the blackout is the
<div id="GraphBox">...</div>
.

Additionally, it's recommended to remove all anonymous function wrappers for better clarity and accuracy:

// Show MicroClean Details window
$("#MicroCleanClick").click(function () {
    $("#GraphBox").show();
    $("#GraphBox").css("z-index", "99999");
    $("#overlay").fadeIn(300);
    loadGraph();
    return false;
});


// Close MicroClean Details Window
$("#overlay").click(function (e) {
    $("#overlay").fadeOut(300, function () {
        $("#GraphBox").hide();
    });
});

Don't forget to include display:none; in the CSS file for #GraphBox to ensure proper functionality of fadeIn and fadeOut.

To make sure the element closes at the same time as the blackout, add $("#GraphBox").hide(); within the following code block:

$("#overlay").click(function (e) {
    $("#overlay").fadeOut(300, function () {
        $("#GraphBox").hide();
    });
});

This code has been tested on both IE and Chrome browsers.

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

Guide to correctly selecting <i> tags within a <p> tag using jQuery

I'm attempting to retrieve the text from the i (italic) elements within a paragraph using this code: $('p').each(function(j, element){ if($(element).is("i")){ console.log("The value is: "+$(element).text()); } }); However, ...

When programming with PHP and JavaScript, managing events' start dates and end dates

In my current project, I am developing a script that deals with events. An event is scheduled to start on 12/02/2016 at 11:20 and end on 01/04/2016 at 8:20. When the end date is reached, I need to trigger a specific action using JavaScript. if (t.getFullY ...

I'm trying to position this div within a table so that it lines up with one of the cells. Can you help me figure out

After implementing the code, here is the current output: <table><tr> <td><div id="adt"></div></td> <!-- 336x280 ad code --> <td id="butw"><div id="butto">Follow @Twitter</div></td> ...

Javascript functions fail to execute as intended

I have a project called calc, which includes various functions such as init. Within this project, there are three buttons that I am adding to the div using jquery. When a user clicks on any of these buttons, it should trigger the inputs function. Based on ...

AJAX success object encounters an uncaught type error

After successfully executing one of my AJAX Posts, there is a logical test with the returned "data" object. Surprisingly, upon page load, JavaScript throws an uncaught type error stating that it cannot read a property of undefined on this line: success: f ...

What is the best way to create a fading footer effect on scroll using jQuery?

Why is my footer not fading in after 1000px like I want it to? Instead, it appears immediately on the screen. I attempted using fadeIn() in jQuery but had no luck. I also tried to make it disappear with fadeOut(), again with no success. Am I missing someth ...

In order to locate a matching element within an array in a JSON file and update it, you can use Node

Good day, I have a script that updates the value in a JSON file const fsp = require('fs').promises; async function modifyNumberInFile() { try { let data = await fsp.readFile('example.json'); let obj = JSON.parse(dat ...

Determining if a replacement took place in the Javascript replace function

I've developed a function that scans through a set of strings and replaces specific patterns: var content = 'Here is a sample string 1/23'; var currentDate = new Date(); var currentMonth = currentDate.getMonth()+1; var currentDay = curre ...

Express.static is having difficulty serving the JSON file

I have a series of inquiries: Currently, I am in the process of developing an application using Angular and Node (Express). 1) Within my Node server, I am serving all static files from my 'static_dir' app.use(express.static(STATIC_DIR)); Insi ...

What is the purpose of encasing the routes within the <Switch> element in react-router, when they seem to function perfectly fine without it

Currently utilizing react-router-dom version 5.2.0. As a practice, I typically enclose all my Route components within a Switch component. For instance: const MyRoutes = () => ( <Switch> <Route path='/route1' exact ...

Utilizing /deep/ and the triple greater than symbol (>>>) within Angular 2

After researching the /deep/ and ::shadow selectors, I've come across conflicting information. In a discussion on Stack Overflow: What do /deep/ and ::shadow mean in a CSS selector? It was noted that Chrome has deprecated the /deep/ combinator and i ...

I'm trying to understand a JSON object that has multiple key names pointing to a single value. How can I properly interpret this in

Encountering an object with a strange key. const obj = { formValues: { 'TOTAL;_null_;_null_;3;_null_': "100" 'billing;_null_;_null_;1;_null_': "Y" 'billing;_null_;_null_;2;_null_': "Y" 'billi ...

JQuery UI allows for resizing blocks vertically only, enabling users to adjust the height of

Is there a way to vertically resize a block using jQuery UI? Most examples show resizing by dragging from the bottom of the block, but I specifically need to be able to resize from both the top and bottom directions. ...

Guide on implementing router-link within a select option dropdown in a Vue.js application

a.vue <template> <div>hi i am component 1</div> </template> <script> export default { name: "a", }; </script> b.vue <template> <div>hi i am component 2</div> </template> <script> ...

Refreshing the Date Display with AJAX Response

Within a view, there is a DisplayFor connected to a DateTime field in the Model. After an AJAX call returns a Date to update the field, I am able to convert the AJAX date into a MM/DD/YYYY format. However, using .val to set the DisplayFor does not reflect ...

Expanding angularjs date filter to support additional date formats

When working with Angularjs, you can utilize the Date Filter to format dates. Is there a way to get the date in the format outlined below? dd(st || nd || th) mm yyyy 1st May 2014 1<sup>st</sup> May 2014 Should I develop a new custom filter fo ...

Is it possible to execute the Go compiler within a web browser?

Just discovered that Go can be compiled to WebAssembly. How awesome! According to this Go documentation, the Go toolchain is actually written in Go itself. This got me thinking, is it possible to run the Go compiler in a browser? Can I create a website w ...

The thumbnail image is failing to load, and when I hover over an image, it moves upwards

I seem to be encountering an issue with a website I uploaded for testing. Everything appears to be working correctly when checked locally in Dreamweaver CS6. However, once the site is uploaded, some issues arise. When hovering over the images, a problem is ...

Preventing a user from inputting a value below 1 in a number input field within Vue 3

I'm working on implementing a number input field in Vue 3 that restricts the user from entering a value less than 1. Currently, I have set the minimum value to 1 to prevent using the input arrows to go below 1: <input min="1" type="n ...

Tips for configuring Webstorm to automatically change double quotes to single quotes when reformatting source code

After using cmd + alt + l in Webstorm to format my JavaScript code, I noticed that double quotes are used instead of single quotes. How can I configure Webstorm to automatically change the double quotes to single quotes in my code? ...