Is there a way to verify if an element possesses a specific style, and if so, alter the style of a different element accordingly?

Could you assist me in achieving a similar effect as demonstrated below:

I have two menus (http://osiyo-nur.uz/osiyo-nur.uz/test6/), one of which is initially invisible. When I hover over the first menu, the second menu becomes visible with an overlay effect on the background. Instead of traditional menus, I am using buttons for this purpose. I attempted to use a condition but it did not yield the desired result. Your help in resolving this would be greatly appreciated.

$(document).ready(function() {
  if ($(".none").css('display') == 'block') {
    $("#overlay").css('display', 'block');
  } else {
    $("#overlay").css('display', 'none');
  }

});
.none {
  display: none;
  width: 60%;
  background: red;
  color: #fff;
  text-align: center;
}

.block {
  display: block;
  width: 60%;
  text-align: center;
  background: red;
  color: #fff;
  margin-bottom: 5rem;
}

.block:hover+.none {
  display: block;
}

.block:hover .overlay {
  display: block;
}

.overlay {
  height: 100%;
  width: 100%;
  position: fixed;
  z-index: 999;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  display: block;
  background-color: rgba(0, 0, 0, 0.6);
  overflow-x: hidden;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <title>GoodGross</title>

  <link href="css\style.css" rel="stylesheet">
</head>

<body>
  <div>
    <!-- HEADER PART STARTS -->
    <div class="main_content">
      <div class="test">
        <a class="btn btn-danger block">Block</a>
        <a class="btn btn-danger none">None</a>
      </div>
    </div>
    <div class="overlay" id="overlay"></div>
    <div class="clear"></div>

  </div>

</body>

</html>

Answer №1

Give this code a whirl:

 $(document).ready(function() {
    $('.block').hover(function(){
        $('.overlay').css('display', 'block');
        $('.none').css('display', 'block');
    });
    $('.none').hover(function(){
        $('.overlay').css('display', 'none');
        $('.none').css('display', 'none');
    });

});

Make sure to incorporate the following CSS into your stylesheet as well:

/*Additional CSS*/
.none{
    position: relative;
    z-index: 9999;
}

Answer №2

using this

$('.block').on('mouseover', function() {
$("#overlay").css('display', 'block');
});

$('.block').on('mouseleave', function() {
$("#overlay").css('display', 'none');
});

$('.block').on('mouseover', function() {
$("#overlay").css('display', 'block');
});

$('.block').on('mouseleave', function() {
$("#overlay").css('display', 'none');
});
.none {
  display: none;
  width: 60%;
  background: red;
  color: #fff;
  text-align: center;
}

.block {
  display: block;
  width: 60%;
  text-align: center;
  background: red;
  color: #fff;
  margin-bottom: 5rem;
}

.block:hover+.none {
  display: block;
}

.block:hover .overlay {
  display: block;
}

.overlay {
  height: 100%;
  width: 100%;
  position: fixed;
  z-index: 999;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  display: none;
  background-color: rgba(0, 0, 0, 0.6);
  overflow-x: hidden;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8>
  <title>GoodGross</title>

  <link href="css\style.css" rel="stylesheet">
</head>

<body>
  <div>
    <!-- HEADER PART STARTS -->
    <div class="main_content">
      <div class="test">
        <a class="btn btn-danger block">Block</a>
        <a class="btn btn-danger none">None</a>
      </div>
    </div>
    <div class="overlay" id="overlay"></div>
    <div class="clear"></div>

  </div>

</body>

</html>

Answer №3

Implementing the jquery hover() method in your code can enhance user interaction:

$(document).ready(function() {
  $("a.link").hover(function() {
    $("#overlay").css('display', 'block');
  }, function() {
    $("#overlay").css('display', 'none');
  });
});

To see a demonstration, visit the following link: https://example.com/demo

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

"Optimizing Background Images with IE 8 Stretch Cover in Bootstrap

Page Broken I've searched all over Stack Overflow for a solution to resolve this background image issue. I'm using Bootstrap for the boxes and removed any margins. The problem arises when setting the background as cover; in IE8, it doesn't ...

I am currently transferring cross-site forgery tokens through jQuery strings. However, on the subsequent page, I create a fresh token which means their original tokens will no longer align

Alright, so I've been storing the tokens in a session: Session::get('token', 'randomtokenstringhere'); Every time a form is submitted, whether successfully or not, I generate a new token and update their session token. But let&ap ...

Encountering the error message "Uncaught Error: [vuex] Getters must be functions, but 'getters.getters' is {}. This occurred while splitting the Vuex store into modules in Vue.js."

As a beginner in VUEX, I am experimenting with building a test application to dive deeper into the world of VUEX. I have organized my VUEX store into modules, where each module has its own getter.js file. Getters, actions, and mutations are imported into i ...

Issues with table nesting functionality

I'm attempting to organize tables in a nested manner, instead of placing a table within each cell. My engineers have advised against simply styling the table to appear nested, and suggested that it would be more effective to wrap each header around th ...

The images on the Shopify platform are becoming increasingly fuzzy

I'm facing an issue where the images I add to my Shopify site using the Brooklyn theme appear blurry unless resized to a small scale. The dimensions of the images are 1748 x 1240 at 300dpi. My intention is to implement a JQuery image slider (lightsli ...

Begin by utilizing the variables published

I have a form on my website that submits data using ajax, allowing for seamless interaction without page refresh. After the form is submitted, I want to dynamically display the user's input by inserting it at the top of the content. However, I am uns ...

An easy way to pass props to a component using useNavigate in React Router

Is it possible to send props directly to a component in React? const goToProjectPage = useNavigate(); useEffect(()=>{ ..... goToProjectPage("/projectpage"); //send props here },[]); ...

Attach the element to the bottom of the viewport without obstructing the rest of the page

My challenge is to create a button that sticks to the bottom of the viewport and is wider than its parent element. This image illustrates what I am trying to achieve: https://i.stack.imgur.com/rJVvJ.png The issue arises when the viewport height is shorte ...

What sets apart the <script> tag with a type attribute from the standard <script> tag in HTML?

Similar Question: Is it necessary to include type=“text/javascript” in SCRIPT tags? While working on my HTML project, I noticed that the JavaScript code within script tags is evaluated even if the type attribute is not explicitly set to "j ...

Warning: React detects a missing dependency within an interval in the effect

A webpage I developed using React and Next.js has the following structure. import Head from 'next/head'; import { useEffect, useState } from 'react'; import Header from '../components/Header'; export default function Home() { ...

How can I retrieve the content of my DIVs using Jquery to submit via post method?

I have a collection of div elements featuring soccer players. I am looking to incorporate a submit button that will allow me to send all the player information from my field to my MySQL database. Is there a way to retrieve the values (IDs and other attri ...

Searching for the row value of specific data within a table using Javascript

I have a PHP table populated with values, and I want to make two of the table data cells editable. The table headers include: Task, Due Date, Staff, and Department. The values in the table data are retrieved from a database using Laravel Eloquent. &l ...

Is there a way to display tiff files in Google Chrome?

I've been struggling with this problem for over 48 hours now, tirelessly searching for a solution. The issue lies within an application built using the ext.net framework on the front end. Specifically, I'm encountering difficulties when it comes ...

Instructions on including a directory in the package.json file for publication on npm

I am facing an issue when attempting to publish a module in the npm repository as it is not recognizing the 'lib' folder. Even though I have included it in the package.json file as shown below, the 'lib' folder contents are not being re ...

Can anyone suggest a method to preview a specific image before uploading on Internet Explorer?

One issue I am encountering is that Internet Explorer does not support the Filereader function in JavaScript. My solution was to send the file via ajax to the server, which would then respond with the file's content. Do you think this approach could w ...

Difficulty with navigation on Chrome for Android (also impacting Bootstrap's website and all other sites utilizing Bootstrap design)

While working on creating a responsive website using Bootstrap, I encountered an unusual issue with navigation specifically in Chrome on Android. After some investigation, I found that the same problem exists on Bootstrap's own website. To see the i ...

The system encountered an error due to the absence of a defined Google or a MissingKeyMapError from the

Currently, I am developing a component that includes ng-map functionality by following the guidance in this tutorial. <div class="content-pane" map-lazy-load="https://maps.google.com/maps/api/js" map-lazy-load-params="{{$ctrl.googleMapsUrl}}"> & ...

Disabling Javascript in Chrome (-headless) with the help of PHP Webdriver

I am experimenting with using Chrome without JavaScript enabled. I attempted to disable JavaScript by adding the --disable-javascript command line argument. I also tried some experimental options: $options->setExperimentalOption('prefs&a ...

Issues with CORS on PUT and POST requests in AngularJS and Node.js are preventing successful communication between the two

I'm encountering a CORS issue with my application. My tech stack consists of Node.js using Express 4 and AngularJS Despite attempting various solutions, I continue to receive the following error for all POST/PUT requests: No 'Access-Control-Al ...

Jquery function for determining height across multiple browsers

I am currently facing an issue with setting the height of table cells in my project. While everything works smoothly on most browsers, Firefox seems to add borders to the overall height which is causing inconsistency across different browsers. If anyone k ...