Implement a CSS transition when switching between images

On my website, I have a feature that switches between a down arrow and an up arrow. You can view it here.

I would like to implement a CSS transition so that there is a brief pause between the switch. How can I achieve this?

Below is the code snippet:

function close_accordion_section(source) {
    $(source).parent().find('.accordion-section-title').removeClass('active');
    $(source).parent().find('.accordion-section-content').slideUp(300).removeClass('open');
}

$('.accordion-section-title').click(function (e) {
    if ($(e.target).is('.active')) {
        close_accordion_section(e.target);
    } else {
        $(this).addClass('active');
        $(e.target).parent().find('.accordion-section-content').slideDown(300).addClass('open')
    }

    e.preventDefault();
});
.accordion {
    overflow: hidden;
    margin-bottom: 40px;
}
.accordion-section {
    padding: 15px;
    border: 1px solid #d8d8d8;
    background: #fbfbfb;
}
.accordion-section-title {
    width: 100%;
    display: inline-block;
    background-image: url("https://cdn3.iconfinder.com/data/icons/google-material-design-icons/48/ic_keyboard_arrow_up_48px-512.png");
    background-size: 5% 100%;
    background-repeat: no-repeat;
    background-position: top right;
}
.accordion-section-title.active {

  background: url("https://cdn3.iconfinder.com/data/icons/google-material-design-icons/48/ic_keyboard_arrow_down_48px-128.png") top right no-repeat;
     background-size: 5% 100%;
    background-repeat: no-repeat;
}
.accordion-section-title.active, .accordion-section-title:hover {
    text-decoration: none;
    transition: color 0.1s linear;
}
.accordion-section-content {
    padding: 15px 0;
    display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div class="accordion">
    <div class="accordion-section"> <a class="accordion-section-title" href="#accordion-1">More information</a>

        <div id="accordion-1" class="accordion-section-content">
            <p>Text.</p>
            <p>
        </div>
    </div>
</div>

Answer №1

There are two simple ways to achieve this effect. One option is using jQuery-UI and including a

.delay(2000) 

at the end of your transition. Alternatively, you can include

transition-delay: 2s;

in your CSS class for the transition. To rotate the arrow image, it is recommended to apply a rotation transition as well.

.rotate{
    -ms-transform: rotate(180deg); /* IE 9 */
    -webkit-transform: rotate(180deg); /* Chrome, Safari, Opera */
    transform: rotate(180deg);
}

If you need further assistance with CSS transitions, you can check out this helpful website:

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 multiline ellipsis without relying on -webkit-line-clamp

Content is dynamically loaded in this p tag. I am looking to implement text ellipsis after a specific line (for example, show text ellipsis on the 4th line if the content exceeds). p { width: 400px; height: 300px; text-align: justify; } <! ...

ReactJS state not being updated due to a nested Axios call

Attempting to fetch data from nested axios calls, successfully retrieving responses from both calls. Struggling to update the prize_pool value within the second axios call. Any assistance would be greatly appreciated. getAllLeague() { axios.get(BA ...

Troubleshooting a Global Search Problem with Regular Expressions in Javascript

I am facing a minor problem. Here is the snippet of code I am working with: var result1=content.match("/<a [^>]*href\s*=\s*[\"']([^>\"']*)[\"'][^>]*>/gi")[1]; This code is not returning any value. Al ...

Having difficulty navigating to a new tab when clicking the mouse middle button or using Ctrl+click in AngularJS

Currently, I am working on an Angular 1.6 application and facing an issue with the code I implemented from stackoverflow. It's not solving my problem. Here is the code snippet: app.run(function($rootScope, $state) { $rootScope.navigate = function($ ...

Encountering NullReferenceException with SharePoint 2007 HttpHandler when using SPContext.Current.Site/Web in conjunction with jQuery

I am working on developing a custom HttpHandler in SharePoint and encountered an issue while coding a simple example: http://pastebin.com/HXLjR2xT. Specifically, I am facing a NullReferenceException on line 35 or 36 when attempting to call my HttpHander pa ...

Is there a way to refresh a webpage without reloading by using Ajax in conjunction with Django Rest Framework?

I am currently working on a Django project where I need to develop a page that uploads real-time data without refreshing the entire page. This data is fetched from a database, so I have set up an API endpoint using Django Rest Framework. However, I am uns ...

Submitting a base64 encoded image as a file stream to a Web API

What I'm struggling with: I have a webpage that utilizes the webcam to take a photo. Upon clicking a button, it saves the current webcam image to an HTML canvas object. The issue arises when trying to send this image from the canvas object to a Web AP ...

Extract information from a php array using autocomplete functionality in jquery/ajax

I have been using the "devbridge autocomplete" plugin, which I found at . However, I am encountering an issue where I am only able to get one value from my search.php page instead of three that I require. Specifically, I am able to retrieve the "value" but ...

Transmitting an array within the POST request payload

My goal is to send an array to my Node/MongoDB server using an AJAX POST request, along with other variables in the body. Check out the client side JS code below: function setupForm(){ $("#add").submit(function(event) { event.preventDefault() ...

Endless stream of text flowing in a continuous line within each paragraph

I am trying to create a unique scrolling effect for each line in a paragraph. The goal is to have each line repeat after one scroll is completed. For example: Let's say there is a line like this in the paragraph: 1,2,3,4, The desired outcome is for ...

Display a triangle underneath the chosen menu option

How can I display a small triangle below the selected menu item, similar to my tag box? I have tried various methods without success. You can view my attempts at this link. Any suggestions on how to achieve this? Thank you! nav { float: right; m ...

The DatePicker feature is functioning properly, however, the Autocomplete feature is not working

I have been working on developing an ASP.NET MVC Application, and surprisingly everything runs smoothly while testing it on localhost. However, once I publish the application, only the datepicker seems to work. I have inspected the folder where my Scripts ...

What is the best way to handle multiple promises when loading a state in Angular?

When loading the /home state, I need to retrieve all users from the database in order to customize the home controller and view based on the logged-in user. Currently, in the :resolve section of the state configuration, I am fetching all 'posts' ...

What are some ways to optimize Ajax requests for improved speed when multiple identical requests are made on a single webpage?

When the webpage is loaded, a block is dynamically created using an Ajax call to retrieve data from another page. This structure is then populated and added to a specific DOM element. However, multiple Ajax calls during page loads are causing delays. Is ...

What could be causing my data to appear as undefined or empty? I am using jQuery.post() to send data from JavaScript to PHP

Issue: I am encountering a problem while sending data to my PHP using jQuery's $.post method. The variable data appears to be undefined for some reason. Let me describe the structure of my code... 1. Here is the button with an onClick function: $dat ...

JavaScript JSON function failing to show

I apologize for my limited knowledge on this matter... We are currently facing an issue with our website's pricing page. The dynamic calculator, which should display the price based on user input of size width and quantity, is not functioning as expe ...

How can I make the hover effect only apply to the text and not the entire box?

I'm wondering how I can make the :hover property only affect individual letters in my navigation bar, instead of hovering over the entire box. * { margin: 0px; padding: 0px; } .navigation-bar { height: 3.2em; background: gray; text-align: ...

What could be preventing me from successfully calling the JavaScript AJAX function in this particular situation?

Here is my code snippet from a smarty template: <form name="transaction_form" id="transaction_form"> <table class="trnsction_details" width="100%" cellpadding="5" > <tbody> <tr> ...

Transforming the date from yyyy-mm-dd to Tuesday, the 25th

My variable is currently in the format: yyyy-mm-dd. I am looking to convert it into the format Tuesday 25th using JavaScript (specifically, the jQuery library). I attempted the following: var now = new Date('2013-06-25').format("l jS"); ...

What is the best way to sequentially process data column by column and incorporate them into a three-dimensional model using three.js?

Currently, I am in the process of creating a 3D model using three.js that will accurately display the position and orientation of a vehicle using accelerometer and gyroscope data. I have collected all the necessary information in an xlsx file, including th ...