When a DIV is clicked, trigger the fadein effect on another DIV; when the same DIV is clicked again, fade

I have a sliding panel on my webpage that reveals the navigation (www.helloarchie.blue). I want the content inside the panel to fade in slowly when it slides out, and then fade out when the user clicks the icon to close the panel. How can I achieve this effect?

CSS: (targeting the div for fading in/out)

.sb-slidebar nav { text-align: left; }

HTML:

<div class="sb-slidebar sb-right sb-style-push sb-active">

<nav>
 <div class="cl-effect-5 blah">
 <a href="http://helloarchie.blue/"><span data-hover="Home">Home</span></a><br />
<a href="http://helloarchie.blue/about"><span data-hover="About">About</span></a><br />
<a href="http://helloarchie.blue/archives"><span data-hover="Archives">Archives</span></a><br />
<a href="http://helloarchie.blue/design"><span data-hover="Services">Services</span></a><br />
<a href="http://helloarchie.blue/contact-me" title="Contact Kaye at Hello Archie"><span data-hover="Contact me">Contact me</span></a><br />

</div>
</nav>
</div>

HTML (this is the icon toggle for opening the panel and initiating the fade in/out effect)

<div class="sb-toggle-right button-square menu">

  <a id="menu-toggle" href="#" class="button2">
  <span class="menu-bar bar1"></span>
  <span class="menu-bar bar2"></span>
  <span class="menu-bar bar3"></span>
  </a>

</div>              

Answer №1

Utilize jquery's .fadeToggle() function, just like in the illustration provided below. For more information on .fadeToggle(), refer to the documentation available here.

$(document).ready(function() {
  $('#click-me').on('click', function() {
    $('#fade-me').fadeToggle();
  });
});
#fade-me {
  background-color: red;
  width: 100px;
  height: 100px;
  display: none;
}
#click-me {
  cursor: pointer;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="fade-me"></div>
<div id="click-me">Toggle Fade</div>

Thus, if implementing this into your code snippet, you may require something similar to:

$(document).ready(function() {
    $('.sb-toggle-right').on('click', function() {
        $('.sb-slidebar').fadeToggle();
    });
});

Answer №2

After reviewing the classname assigned to the div element in question, it appears that a sliding plugin is being used for panel transitions. Without insight into the specific JavaScript code being utilized, it's challenging to provide a precise solution. One potential approach would involve referencing the documentation of the plugin to identify methods that can be employed to trigger functions at the onset and conclusion of animations or slides. Within these designated methods, you could include instructions to add or remove a custom classname responsible for managing the fade-in and fade-out effects of the div. This implementation might resemble the following:

JavaScript:

onSlideStart: function() {
        $(this).removeClass('fade-me-in');
},
onSlideEnd: function() {
        $(this).addClass('fade-me-in');
}

CSS

div {
    opacity: 0;
}

div.fade-me-in {
    opacity: 1;
    -webkit-transition: opacity 0.3s;
    transition: opacity 0.3s;
}

If this suggestion doesn't fully address your requirements, please share the relevant JavaScript snippets for further assistance.

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

Implementing a function in jQuery to create a "Check All" and "Uncheck All" button

Can someone please guide me on how to implement a check all and uncheck all functionality when I check individual checkboxes one by one? Once all checkboxes are checked, the 'checkall' checkbox should automatically be checked. Below is the code s ...

Bootstrap slider with fading in and out effects

I am attempting to create a bootstrap slider that fades in and out when transitioning between slides, similar to the effect demonstrated in this template.. I am using Visual Studio 2010 with ASP.NET. The issue I'm facing is that when the image change ...

Is the img tag supported by html2image?

I've been diving into the functionality of the html2image package and noticed that it's having trouble locating my locally stored images. My code snippet looks like this: from html2image import Html2Image hti = Html2Image() html_str = "&q ...

CSS slideshow animation is not functioning properly

Hey there, I'm new around here and I've got a question for you all. Please bear with me if I make any mistakes. So, I'm attempting to create a simple CSS slide image. In my animation code, I want the picture to fade from the left every time ...

Proper positioning of popover ensures it does not exceed the boundaries of its parent

In my ngprime table, the header row contains a column field with a popover set to display at the top. However, it is covering the actual field instead of appearing above it. This issue arises because the popover cannot display outside of its parent div, ca ...

Retrieve a boolean value through an Ajax call from a C# function using T4MVC

I have a search bar on my website with the following code: <form onsubmit="return IsValidCustomer()"> <input class=" sb-search-input" placeholder="Search for a customer..." type="text" value="" name="search" id="search"> <input cl ...

Why is the Material UI React select not selecting all children except for the last one?

I have a challenge with selecting specific children: const useStyles = makeStyles(theme => ({ icons: { "&>*": { backgroundColor: "red", }, }, })) This is how it looks in JSX: <Grid item> < ...

JavaScript Tab Fade Effect

I have a tab system that utilizes JavaScript to switch tabs. I am trying to implement a fade in and out effect when switching tabs. The current JavaScript simply adds or removes the clicked tab selected by the user. I have managed to partially achieve the ...

Displaying a div on click using Jquery will only impact one div at a time

I am encountering an issue with my WordPress setup. Within my loop, I have a clickable link that toggles a div to show or hide content. However, since each item in the loop uses the same class, clicking on one link activates all of them simultaneously. &l ...

After populating dropdown values with Ajax in Yii2 Kartik, the dependent dropdown does not update the selected value through Ajax

Are you looking to update the selected value of a dependent drop-down menu? Even after using ajax to load values into the dependent drop-down, the following code does not seem to be working: $("#dependentDropDownID").select2("val", data); This code appea ...

JavaScript - Clear the localStorage when closing the final tab of a website

Currently, I am working with AngularJS and utilizing $window.localStorage to store the username of a logged-in user. Since localStorage needs to be explicitly deleted, I have implemented an event listener for $(window).on('unload', function(){}) ...

Why does it seem like only one div is being added?

I am facing an issue with dynamically appending multiple div elements. Despite my efforts, only one div element is showing up on the browser when I try to test the code. I have searched for similar problems but could not find any solutions. Any assistanc ...

Waiting for the listener script to finish its task in an Ajax call and then informing the user

I have developed a unique program that allows users to submit test cases from a specific webpage (main.php). The webpage triggers an ajax request to insert user data into MySQL using the file insert.php, with the value done=0. Subsequently, there is a list ...

The height of the content in the polymer core-scaffold cannot be set to 100%

I am working with a polymer element that I have defined. The main objective is to make the conversation_container element have a height of 100% so that the message_box_container can be positioned at the bottom of the entire panel using position: absolute; ...

Determine future dates based on selected date and time

When a user selects a date in the datetimepicker, I want to automatically set three additional dates. The first date will be the selected date + 28 days, the second date will be selected date + 56 days, and the third date will be selected date + 84 days. I ...

What is the best method for inserting space between two divs?

I need to create more space between the last two cards and the image at the bottom, but this spacing should increase as I resize the browser window. Can anyone help me with this? https://i.stack.imgur.com/rq9t2.png https://i.stack.imgur.com/tOikx.png Th ...

What is the process for including the posting date in the JSON format while using the Instagram

Struggling to incorporate the date into my JSON Instagram feed has been a challenge for me. For reference, here is a demonstration on JSFiddle: http://jsfiddle.net/galnova/p74jy3sk/ The following code snippet includes the commented-out section related to ...

What could possibly be causing issues with this query to the database?

-Problem Still Unsolved- I am facing issues with calling a database, retrieving all the rows from a table and storing them in an array. I then try to pass this table as JSON data to my JavaScript and use it as parameters for a function. But when I run the ...

Attempting to make initials fade and slide out upon mouseover using jQuery

I've been experimenting with jQuery to create a unique effect where hovering over my initials in the header expands the containing div and reveals my full name letter by letter. However, I'm facing some challenges and could use some guidance on t ...

Is it possible for me to add images to the input file individually before submitting them all at once?

When images are inserted one by one, the 'input file' only reads one picture at a time. However, when images are inserted in multiple quantities, the result is displayed for each image that the user inputs. window.onload = function() { //Ch ...