Animate downwards pointing arrow to rotate 180 degrees upon activation

Is there a way to create a dropdown arrow that rotates when opened?

I've experimented with different approaches, such as using CSS methods like

.bd-aside .btn[aria-expanded="true"]::before {transform: rotate(90deg);}
, along with ::after and ::before elements, but none have had the desired effect.

Dropdown Inactive:

https://i.sstatic.net/YjKylIpx.png

Dropdown Active:

https://i.sstatic.net/KnXQbXvG.png

The goal is for the arrow to smoothly rotate 180 degrees in 0.15 seconds.

// Navbar Dropdown
$(".ctx-dropdown-toggle").click(function () {
    $(this).next(".dropdown-menu").slideToggle(600);
});
@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700;800&display=swap");
@import url("https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="caa8a5a5beb9beb8abbae7a3a9a5a4b98afbe4fbfbe4f9">[email protected]</a>/font/bootstrap-icons.min.css");

/*navbar styling*/
.navbar {
    height: 60px;
}

.navbar-brand {
    --bs-navbar-brand-padding-y: 0px;
    --bs-navbar-brand-margin-end: 0px;
}

...
...

/*dropdown styling*/
.dropdown-menu {
    background: #111;

    ...
}

.bi-chevron-up {
    display: inline-block;
}
/*end dropdown*/

<head>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1" />

       ...

        </head>
        ...

A snippet of my navbar showcasing the dropdown with the arrow next to it has been included for reference. Hopefully this provides some insight!

Answer №1

To rotate the caret, simply add a class with transform: rotateZ(180deg) to it. It's recommended to set the default rotate value to 0 so that it can be smoothly transitioned.

// Dropdown Animation
$(".ctx-dropdown-toggle").click(function() {
  $(this).next(".dropdown-menu").slideToggle(600);
  $(".chevron-icon").toggleClass("rotated")
});
@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700;800&display=swap");
@import url("https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ccaea3a3b8bfb8beadbce1a5afa3a2bf8cfde2fdfde2ff">[email protected]</a>/font/bootstrap-icons.min.css");

/* Styles for Navbar and Dropdown */

.navbar {
  height: 60px;
}

/* More styles... */

.chevron-icon {
  transform: rotateZ(0);
  transition: 150ms;
}

.chevron-icon.rotated {
  transform: rotateZ(180deg);
}

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

Stop scrolling on the body of the webpage

I am struggling to find a solution to completely disable scrolling on the HTML body. I have experimented with different options, but none seem to work as desired: overflow: hidden; did not disable scrolling, only hid the scrollbar. position: fixed; w ...

Utilizing AngularJS to handle the reception and storage of HTML entities

I am having an issue storing and displaying HTML content (using an HTML editor) in my AngularJS WebApp. The problem is that the code appears as plain text. Here is the JSApp code: $scope.SkipValidation = function (value) { var decoded = $("#showtext" ...

Troubleshooting problem with Django Material's navigation bar

Currently, we are utilizing Django Material (MaterializeCSS as CSS framework) for a new project in progress. We have encountered an issue with the language selector located in the admin navbar. Interestingly, this problem only occurs in Firefox and not in ...

What could be the reason for the HTML canvas not displaying anything after a new element is added?

How come the HTML canvas stops showing anything after adding a new element? Here is my HTML canvas, which works perfectly fine until I add a new element to the DOM: <canvas class="id-canvas", width="1025", height="600"> ...

Increment counter when a key is pressed in Angular 4 and decrement when the backspace key is pressed

As a beginner in Angular, my goal is to create a feature where: The character count in a label increases as text is entered into a textarea. When the backspace key is pressed, the counter should decrease. If the user attempts to enter more characters tha ...

Achieving a consistent border-radius effect during hover transitions

I designed a div that initially displays an image, but upon hovering over it, a second div with text and a solid colored background appears to mask the original content. To see what I'm talking about, check out my jsfiddle: 'Mask on Hover' ...

What is the relationship between html, body, and window when scrolling through code?

I've been working on adding a scroll-to-top button to my website. After doing some research online, I came across this code snippet: $('html, body').animate({scrollTop:0}, 'slow'); It's interesting that they are trying to scr ...

Utilizing Vue.js to Showcase Real-Time Data on an HTML Page

I am attempting to showcase the bill structure on an HTML page by retrieving data in Vue and Axios. There is a table where orders are listed, with each row having a "Print" button. When this button is clicked, I want to display the specific order details i ...

Issue with Jquery functionality on IE9 Release Candidate

Recently, I made the switch to IE9 RC (which, in my opinion, is not too shabby for a Microsoft product so far - though there's still time for them to mess it up! Please refrain from starting a browser war in the comments section by sharing your though ...

Expanding your knowledge of AngularJS: utilizing ng-click to interact with elements

After a user clicks on an element in my app, I have some logic that runs. For example: html <h3 ng-click="showAlert('text')">this is text! (try to click and select)</h3> js $scope.showAlert = function(text) { console.log(' ...

What is the best method to retrieve child elements from a class list object?

Seems like I have a similar content class <div class="parentclass"> <div class="childClass"> </div> <div class="childClass"> </div> <div class="childClass"> </d ...

Techniques for retrieving elements from HTML using jQuery

I'm developing a feature that allows users to add videos to playlists by clicking on a link in a popover. The challenge I'm facing is extracting the video_id and the selected playlist when the user interacts with the popover. Any tips on how to a ...

Utilize JavaScript conditions to dynamically apply styles within your web application

I am facing a challenge with managing two separate <style> tags that each contain a large number of styles and media queries. The issue is that one set of styles is intended for desktop users, while the other is meant for mobile users. When both se ...

How can I create a unique overlay popup for each item in an iterated list using Django template?

Generating an iterated list of titles from context received by the template in Django is simple: {% for instance in object_list %} <li>{{instance.international_title}} </li> {% endfor %} CSS makes it easy to create a popup overlay as well: # ...

What is the best method for sending the styled and checked option via email?

Just finished customizing the checkboxes on my contact form at cleaners.se/home. Here's my question: If I select "telefon," how can I ensure that this option is sent to my email? In Contact Form 7, I used to simply type a shortcode. Is there a simila ...

Is there a way to position an image to the left of the container in Jinja templating while floating it?

I am currently working on a project using Flask that utilizes Jinja templates. In my layout.html file, there is a grey colored container that extends to all child pages. I have a specific page that extends the layout.html where I want to place an image flo ...

Track when a user clicks within a specific container in VueJS, excluding clicks on a specific child element

On my page, I have multiple choice question options that are structured like this: https://i.sstatic.net/oMH7t.png The following is the HTML code for the options section so far: <div v-for="(option, index) in optionsForFrontend"> <di ...

A three-argument function designed for generating a prepend element

Hey everyone, this is my first time asking a question on this platform, so bear with me if I sound a bit off. I'm currently diving into the world of Javascript and I recently attempted to create a function with 3 arguments: the parent element, the ele ...

I am looking to create a feature for my table that adjusts its color scheme based on whether the number is odd or even

My current code is designed to change the background color of td elements for odd and even rows. However, when a new high score is entered, a new td is added but it does not get colored automatically as intended. I am facing an issue where the code is not ...

There are mistakes in the code that I am struggling to fix

I am encountering an issue where my website only functions properly on Firefox and not on Chrome. However, when I run the HTML using NetBeans on Chrome, the website works fine. I'm unsure of what to do as I need to submit this project within the next ...