What is the best way to initially hide a div using slide toggle and then reveal it upon clicking?

Is there a way to initially hide the div tag and then animate it in a slide toggle effect? I attempted using display:none on my '.accordion_box' followed by show() in slideToggle, but this results in adding the CSS property display: block. My goal is to create an accordion slide that expands from left to right.

$(".slide-toggle").click(function(){
$(".accordion_box").animate({
width: "toggle"
});
});
#about .about_content .accordion_content {
  font-size: 0;
  min-height: 700px;
  padding-top: 50px;
  text-align: left;
}

#about .about_content .accordion_content .accordion_box, #about .about_content .accordion_content .accordion_toggle {
  font-size: 16px;
  display: inline-block;
  vertical-align: top;
}

#about .about_content .accordion_content .accordion_box {
  background: blue;
  min-height: 200px;
  width: 90%;
}

#about .about_content .accordion_content .accordion_toggle a.slide-toggle {
  display: block;
  width: 50px;
  height: 200px;
  background: red;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
       <div id="about">
            <div class="wrapper">
                <div class="about_content">
                    <h3>About Us</h3>
                    
                    <div class="accordion_content">
                        <div class="accordion_box">

                        </div>
                        <div class="accordion_toggle"><a href="#about" class="slide-toggle"></a></div>
                    </div>
                </div>
            </div>
        </div>

Answer №1

If you want the slider to move horizontally as you mentioned, without altering any other part of your code, you can apply style="display: none" directly on the .accordion_box div and then include display: inline-block; in your CSS for the respective selector. Here's an example:

$(".slide-toggle").click(function() {
  $(".accordion_box").animate({
    width: "toggle"
  });
});
#about .about_content .accordion_content {
  font-size: 0;
  min-height: 700px;
  padding-top: 50px;
  text-align: left;
}

#about .about_content .accordion_content .accordion_box,
#about .about_content .accordion_content .accordion_toggle {
  font-size: 16px;
  display: inline-block;
  vertical-align: top;
}

#about .about_content .accordion_content .accordion_box {
  background: blue;
  min-height: 200px;
  width: 90%;
  display: inline-block;
}

#about .about_content .accordion_content .accordion_toggle a.slide-toggle {
  display: block;
  width: 50px;
  height: 200px;
  background: red;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="about">
  <div class="wrapper">
    <div class="about_content">
      <h3>About Us</h3>

      <div class="accordion_content">
        <div class="accordion_box" style="display: none;"></div>
        <div class="accordion_toggle">
          <a href="#about" class="slide-toggle"></a>
        </div>
      </div>
    </div>
  </div>
</div>

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

What is the best way to ensure the options/choices div reaches its ideal width?

Check out my StackBlitz project that I've set up In the styles.css file, you'll notice that I defined a fixed width of 650px for the option dropdown div, which is currently working fine @import '~bootstrap/dist/css/bootstrap.min.css'; ...

What is the best way to retrieve the value of a selected radio button with YUI?

Here is the structure of my radio buttons... <div id="test"> <input name="test1" value="a" type="radio"> <input name="test1" value="b" type="radio"> <input name="test1" value="c" type="radio"> </div> What is the best w ...

Change the class name using jQuery when scrolling

Currently utilizing bootstrap as my primary css framework. My goal is to dynamically toggle a class on the navbar once the user scrolls past the prominent header image located at the top of the website. UPDATE: Admitting I made an error and had a momenta ...

Establish characteristics for the temporary print document

Struggling to configure the properties of a temporary file created for later printing by the user. Here's a breakdown of the process: User clicks on "Print Map Area" button on the website. A menu appears asking for preferred dimensions (e.g. A4 ...

Having difficulty including a new key-value pair to a JSON object while using another JSON object

Looking to merge key value pairs from one JSON object into another. I've searched through various stackoverflow threads for solutions, but haven't found one that works for my specific scenario. const primaryObject = { name: "John Doe", ag ...

Is it acceptable to utilize display:none in order to generate multiple CSS navigation bars for a responsive website?

I designed a CSS navbar that looks great on larger screens, but unfortunately it doesn't reflow well on mobile devices. One solution I thought of was to create a separate, mobile-friendly navbar and position it on top of the desktop version while hidi ...

Guide to dynamically loading a component using a variable name in Vue.js?

Is it possible to dynamically load a component in a vue.js application using a variable name? For example, if I have the following component registered: <template id="goal"> <h1>Goal:{{data.text}}</h1> </template> Instead of di ...

Irregular dimensions of div elements following automated selection

My tile div can be selected using the mouse or a timed event. Here are the states of selected and unselected : Not .selected .selected applied .tile { height: 70px; padding: 5px 10px 5px 10px; margin: 8px auto 0px auto; width: 280px; ...

Tips for transmitting one or multiple data using jquery.ajax

I found this code on stackoverflow and it is working well for uploading multiple files. However, I am facing an issue where I cannot send additional parameters along with the file upload. Despite trying various methods, I have been unsuccessful in sending ...

Unable to define an object within the *ngFor loop in Angular

In order to iterate through custom controls, I am using the following code. These controls require certain information such as index and position in the structure, so I am passing a config object to keep everything organized. <div *ngFor="let thing of ...

The table's content extends beyond the confines of the page

I have an HTML page where I am embedding an SSRS report. The report extends beyond the page as shown in the image below: This is the table that is generated: <table cellpadding="0" cellspacing="0" id="ctl00_MainContent_FiveYearReportViewer_fixedTable" ...

Refreshing the page is the only way to activate the jQuery function

I am currently using the $.getJSON(...) method to fetch JSON data (images) for my HTML web page. The getJSON() function is triggered once the DOM has fully loaded: $(document).ready(function() { Subsequently, I am utilizing the montage.js library to orga ...

The 'length' property is not found within the 'HTMLElement' type

Can someone assist me with looping over the number of nav-items I have? I am encountering an error that says: Property 'length' does not exist on type 'HTMLElement'. I understand that changing document.getElementById('nav-item) to ...

Tips for customizing the appearance of the span tag within the option text of an HTML select

Unique Link In my current situation, I am facing an issue where the asterisk in the first option of my HTML select element should be displayed in red color. Despite my efforts to style it, the asterisk always appears in the default black color. I have pr ...

Looping through AJAX requests in JavaScript

I am attempting to make REST API requests in order to retrieve data and display it on a website. Although I have created a for loop to gather the data, I am encountering an issue where the data is not being displayed on the website. Upon checking with th ...

The issue with jqTransform not displaying the select box value on a hidden contact form

Could really use some assistance here and apologize if it's a hassle: Link to contact form To view the contact form, simply click the "Contact" button in the top left corner. The jqTransform jQuery plugin is being used to style it. Initially, it&apo ...

Improving user experience with CodeIgniter's form validation powered by AJAX and jQuery

I am currently attempting to validate certain fields using AJAX in CodeIgniter, but I'm having some difficulty getting it to work correctly. This is the AJAX code snippet that I have: var timeout = null; $(document).ready(function(){ $('. ...

What steps can I take to address the problem in iOS 17 where sound is coming from the earpiece instead of the speaker during camera activation?

I have a Progressive Web App where I use the getUserMedia() API to access the camera and HTML audio tags for handling media content. However, ever since updating to iOS 17, I've faced an issue where audio plays through the earpiece instead of the medi ...

Is it beneficial to incorporate keys into an express instance for improved functionality?

If I want to pass information from my index.js file to multiple endpoints across different routes, is it sufficient to attach a custom key to the express instance (app)? For instance, if I am using socket.io and want multiple endpoints to emit from the i ...

Utilize CSS to incorporate an image as the background of a <div> element

I'm a beginner in the world of HTML/CSS and this is my practice page. I have a section with an image of a person, and I'd like to add a quote next to the image. However, I'm struggling to make the image fill the entire width and height of th ...