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

Creating interactive navigation bar effects with scroll and click functionality using jQuery

Is there a way to make the navigation highlight when a user clicks on it and also scrolls to the corresponding section? Currently, I am facing an issue where only the third navigation event highlights, most likely because when navigating to the fourth or f ...

Displaying list items with <output> compared to using <ul>

While it's commonly known that the <ul> tag is used to display <li> items, I recently discovered that the <output> tag can also be utilized for this purpose after reading about it here. In my current project, I have been using the & ...

Positioning HTML elements using CSS and avoiding the use of tables

I'm struggling with my clear CSS declarations. This is how I'd like it to appear: View the Fiddle demo HTML: <div id="timesheeteditor"> <div id="weekselector"> <div>Week 1</div> <div>Week 2</div> ...

Sorting the Czech alphabet with the help of Tablesorter

Utilizing the tablesorter characterEquivalents extension as outlined in this documentation. I have created a similar extension for Czech characters, but the sorting is not functioning correctly for certain characters - like \u017d $.extend( $.tables ...

Customize specific styles for individual divs one at a time (without the use of jQuery)

Can you assist me with this issue? I am trying to display the <span class="badge badge-light"><i class="fa fa-check-circle"></i></span> tag (initially set to "visibility: hidden") when clicking on a div with the class "role-box". He ...

How do I switch between liking and unliking a post using Ajax's success response?

I have successfully implemented code to insert or delete likes from the database, and it functions correctly upon page refresh. However, I am struggling to figure out how to make it toggle upon clicking. I have attempted various online solutions without su ...

Struggling to find solutions for debugging HTML codes in Visual Studio Code and linking my CSS page to my HTML page

I ran into some issues with linking my CSS stylesheet to my HTML pages. I tried using the <link rel="stylesheet" href="style.css"> command, where style.css is the name of the file. However, for some reason, it wasn't working ...

Enhance the current menu item in WordPress by assigning a class to the anchor tag

function updateActiveClassOnMenu($item_output, $item, $depth, $args) { $menu_locations = get_nav_menu_locations(); if ($item->menu_order == 1){ $item_output = preg_replace('/<a /', '<a class="active" ', $item_o ...

Centered horizontally are images that have been floated

How can I align images with different widths when they are all floated right? I want them to be aligned vertically below each other. For the best display, please view in fullscreen on your computer as the example window is small. .compressor{ height: 1 ...

In what way can the jQuery .each() function make use of the index as a variable?

Consider the jQuery .each() function, which comes with a useful feature. For example: $('.element').each(function(index){ console.log(index); }); Here, you can access the index of the currently selected element using the "index" variable. ...

Background image not displaying in new tab after Chrome extension installation

I have been developing a Chrome extension that alters the background image of a new tab. However, I have encountered an issue where the background image doesn't change the first time the extension is loaded. This problem has also occurred very occasi ...

Generate real-time dynamic line charts using data pulled directly from a MySQL database

I am in search of guidance on developing a real-time line chart that can dynamically update based on data fetched from MySQL. I need an example or reference on how to achieve this functionality without having to refresh the webpage every time new data is ...

Utilize Ajax to showcase MySQL query outcomes upon onClick() event

As a newcomer to Ajax scripts, I am currently working on creating a script that will showcase MySQL query results when a user clicks on a specific link. My approach involves utilizing the onClick() function to trigger an Ajax script. Below is a snippet of ...

Is there a way for me to verify that the value I retrieved from my AJAX request was successfully passed to my

The login event will be triggered by this action $('#btnLogin').click(function(){ //var data = $('#loginForm').serialize(); var email = $('#loginEmail').val(); var password = $('#lo ...

Feature exclusively displays malfunctioning image URLs for the web browser

Hello everyone! I've been diving into learning JavaScript and recently attempted to create a function that randomly selects an image from an array and displays it on the browser. Unfortunately, despite my efforts, all I see are broken link images. Her ...

Awesome C# PDF Printing Solution [closed]

This question does not comply with our Q&A standards and guidelines. To maintain the integrity of our platform, we require answers to be factual, supported by references or expertise. However, this question may provoke debates, arguments, polls, or pro ...

Comparing React's Styled-components, JSS, and Emotion: Which is

As a CTO, I am faced with the decision of choosing between three popular CSS-in-JS libraries: jss emotion styled-component. I will keep this question focused and avoid straying into subjective territory. If necessary, I will answer it myself by asking sp ...

What is the best way to make the first LI elements stand out in a nested structure by applying bold

I had an idea like this: #list li > a { font-weight: bold; } However, I only want the top level items to be made bold, not nested LI's within LI's -- hope that makes sense?? :) EDIT | <ul id="list"> <li><a href="#"& ...

Modify the background hue of the checkbox to resemble a button when selected

Is there a way to create a checkbox that resembles a button in appearance? I have managed to achieve this, but I am facing an issue with changing the background color of the button when it is checked. Currently, the button turns light-grey when checked, bu ...

Using SVG background images in Internet Explorer versions 7 and 8: a guide to HTML, CSS,

I have created a unique SVG image to use as a background, but it's not displaying in Internet Explorer 8 and earlier versions. I tried using tools like or http://code.google.com/p/svgweb/, but they only support SVG for IMG and Object elements, not ba ...