What is the secret to keeping links opaque even after they have been hovered over and their target is visible?

There are four links on my page that toggle the visibility of different divs. You can see them in action here.

The code for the links is shown below:

<li class="togglelink fadein button" data-block="albums" id="togglealbums">Albums</li>
<li class="togglelink fadein button" data-block="about" id="toggleabout">About Me</li>
<li class="togglelink fadein button" data-block="contact" id="togglecontact">Contact</li>

and

<img src="images/info.png" class="button nav_button fadein toggleinfo" id="info" alt="Show Info Pane" title="Show Info Pane">

The CSS for the fadein class includes:

.fadein {opacity:0.5; transition:opacity 0.5s; -webkit-transition:opacity 0.5s; -moz-transition:opacity 0.5s; -ms-transition:opacity 0.5s;}
.fadein:hover {opacity:1.0;}

The jQuery responsible for showing and hiding the target divs is:

$('.togglelink').on('click',function() {
  var id = $(this).data('block');
  $('#'+id).fadeToggle('slow').siblings('.toggleblock').fadeOut('fast');
});

$('.toggleinfo').click(function() {
  $('.info').fadeToggle('slow');
});

My goal is to keep the link that targets an open div at opacity: 1.0. I attempted to achieve this by toggling the active class on click.

$('.togglelink,.toggleinfo').click(function() {
  $(this).toggleClass('fadein active');
});

However, there are two issues with this approach: the links do not return to semi-transparent when using the close buttons on the divs, and clicking multiple links can result in multiple fully opaque links.

The code for the close buttons is similar to:

<img src="images/close_pane.png" class="togglelink fadein close_pane button" data-block="albums" alt="Close Album List" title="Close Album List">

If anyone has suggestions on how to resolve these issues, I would greatly appreciate it. Thank you!

Answer №1

$('.togglelink,.toggleinfo').on('click', function() {
    $(this).siblings('.active').toggleClass('fadein active');
    $(this).toggleClass('fadein active');
});

$('.close_pane').on('click', function(){
    $('li[data-block="'+ $(this).data('block') +'"]').removeClass('active').addClass('fadein');
});

Answer №2

var id = $(this).data('block'); should be changed to

var id = $(this).attr('data-block');

Additionally, instead of using the fadein class, consider using jQuery's fadeIn() function. Using jQuery's fadeIn() modifies the inline style of the element, which could be the reason it's not functioning properly.

$('.togglelink').click(function() {
  var id = $(this).attr('data-block');
  $('#'+id).fadeToggle('slow');
  $(this).siblings().fadeOut('fast');
});

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

Error message: "The input type 'application/json' is not valid for Ajax POST calls"

I am facing an issue when trying to make an ajax call. I keep receiving error code 415, which indicates an unsupported media type. I have attempted to resolve this by setting the header Content-Type : application/json, but unfortunately, the problem persis ...

Error encountered in jQuery Datatables: aData variable is not defined

I am having an issue with a jQuery datatable that is using an Ajax data source. This is how the table is set up: $("#tblNotes").DataTable({ "ajax" : { "url": "/projects/ajaxGetProjectNotes/", "type" : "post", ...

Textbox value disappears after being updated

When I click on the edit link (name), the value from the database is displayed as a textbox. However, when I update another normal textbox (age), the value in the edit link textbox disappears. Strangely, if I input a new value into the edit link textbox, i ...

Tips for maintaining the nested collapsible table row within the main table row in a React MUI table

I am working on implementing a Material UI (MUI) table that includes collapsible table rows. The challenge I am facing is maintaining consistent border and background colors across all the rows, even when some are collapsed. Currently, the separate rows ar ...

The static menu is malfunctioning and is disrupting the smooth operation of the website

I've created a custom Wordpress menu that should switch to a different layout when scrolling down. While the functionality works fine, I'm facing an issue where a portion of the page is lost every time the menu transitions from "relative" to fixe ...

Jquery form submission error occurring with file upload functionality

For the solution to this issue, please check out this fiddle here An inconsistency can be observed where the $('#photoform').serialize(); does not retrieve values for the form field, specifically the file field. What would be the appropriate ap ...

Content below divs that are fixed and absolutely positioned

I have a design layout similar to this (a small snippet) and I am facing an issue where the text within .content is not clickable. The positioning of #gradient is fixed due to the background image, and #empty has an absolute position to cover the entire bo ...

Modify the parent div's style if there are more than two children present (CSS exclusive)

Is there a way to use the same class, like .outer, for both divs but with different styling for the parent element when there are more than two children? Kindly refer to the example provided below: .outer1{ border: solid 6px #f00; } .outer2{ b ...

Tips for implementing jQuery validation with CakePHP 3.0

Just starting out with Cake PHP and I have a question. Can someone show me how to implement custom validation using jQuery in Cake PHP 3.0? Here is the code from my add.ctp file: <h2>Add New User</h2> <!-- link to add new users page --&g ...

Tips on keeping the size of a react-bootstrap modal constant and enabling scrolling instead of expanding

<Modal size="lg" scrollable show={showInvModal} onHide={handleCloseInvModal}> <Modal.Header closeButton> <Modal.Title>Check out our latest items!</Modal.Title> </Modal ...

Ways to conceal Bootstrap-designed elements behind a fullscreen overlay

I'm attempting to create a transparent layer to conceal the entire content of my page behind it. It works fine without the Bootstrap columns, but as soon as I add the columns for responsive design, it stops working (or maybe I'm just not understa ...

Tips for displaying the UI Slider value on multiple fields simultaneously

I'm trying to display the value of a UI range slider in an input box. I have successfully done this, but now I want to show the same value in another div as well. Currently, I am able to capture the slider's value in the input box, but I also ne ...

Photo on vertical display

I have been working on displaying dynamic photos from a backend file and looping through them. I have successfully displayed the images vertically using CSS. vertical-align: middle; However, when I tried to add a photo name for each image, the positionin ...

Using a PHP variable to trigger the jQuery .show() function

I'm attempting to trigger jQuery .show() events based on PHP variables. Below is my PHP code (retrieved from a form submission on another page): $last_pic_displayed = trim($_POST["last_pic_displayed"]); if (strlen($last_pic_displayed) <= ...

Unable to position divs next to each other in Firefox, yet successfully achieved in Chrome

I have successfully placed two divs side by side using the following markup, as shown in image 1, but this layout only works on Chrome. However, Firefox renders it differently as seen in Image 2. Is this a known issue that I overlooked? How can I resolve t ...

Achieving the desired alignment of text and button can be easily done using Bootstrap

Is there a way to align text buttons both to the left side and right side using bootstrap? I have included a screen and code below. I apologize if this question seems simple, but I am new to this field. I would like to know how to achieve this, and it woul ...

Submit Button Field - HTML ButtonFor

Being relatively new to MVC Razor and web development, both front-end and back-end, I'm in need of a button that can send a stored value to the controller/model. I attempted to mimic the functionality of Html.TextBoxFor by giving it attributes similar ...

How can I successfully add an element to a nested array without making any mistakes in saving it?

Hello everyone, I'm new here. I previously posted about a similar issue, but now I have a different one. I am encountering this object: singleChat = [ { "chatid": 10000414, "connected": true, "index": 0, ...

Loading a .css file in advance using NextJS

We have integrated NextJS and Material-UI into our website, but we are facing an issue with FOUC (Flash of Unstyled Content) upon page loading. After some investigation, I discovered that the JS files are loading faster than the CSS file, causing the probl ...

The flex grow animation fails to activate when the Bootstrap 4 style sheet is added

Trying to implement transitions with flex grow has been a challenge. It works smoothly without any issues, but as soon as I add the bootstrap 4 style sheet, the transitions stop working. I haven't even started using the bootstrap 4 classes yet, it&apo ...