Trigger webkit animations with a click rather than on hover

I am struggling to initiate the animations when the .menu is clicked on instead of when it's hovered over. What code should I include in my clickeffect function to start the animations onclick?

Unfortunately, the system is not allowing me to post the question so I'm adding some extra text here.

function showmenu(){
var menu = document.getElementById('mobile-menu'), maxH="148px";
if (menu.style.height == maxH){
menu.style.height = "0px";

}else{
menu.style.height = maxH;
}
}

function clickeffect(){
var burgermenu = document.getElementByClassName('menu');
}
.menu {
position: relative;
display:  inline-block;
width: 30px;
height: 30px;
margin: 25px;
}
.menu span {
margin: 0 auto;
position: relative;
top: 12px;
}
.menu span:before, .menu span:after {
position: absolute;
content: '';
}
.menu span, .menu span:before, .menu span:after {
width: 30px;
height: 6px;
background-color: white;
display: block;
}
.menu span:before {
margin-top: -12px;
}
.menu span:after {
margin-top: 12px;
}

.menu span {
-webkit-transition-duration: 0s; transition-duration: 0s;
-webkit-transition-delay: 0.2s; transition-delay: 0.2s;
}
.menu:hover span {
background-color: rgba(0,0,0,0.0);
-webkit-transition-delay: 0.2s; transition-delay: 0.2s;
}
.menu span:before {
-webkit-transition-property: margin, -webkit-transform; transition-property: margin, transform;
-webkit-transition-duration: 0.2s; transition-duration: 0.2s;
-webkit-transition-delay: 0.2s, 0s; transition-delay: 0.2s, 0s;
}
.menu:hover span:before {
margin-top: 0;
-webkit-transform: rotate(45deg); transform: rotate(45deg);
-webkit-transition-delay: 0s, 0.2s; transition-delay: 0s, 0.2s;
}
.menu span:after {
-webkit-transition-property: margin, -webkit-transform; transition-property: margin, transform;
-webkit-transition-duration: 0.2s; transition-duration: 0.2s;
-webkit-transition-delay: 0.2s, 0s; transition-delay: 0.2s, 0s;
}
.menu:hover span:after {
margin-top: 0;
-webkit-transform: rotate(-45deg); transform: rotate(-45deg);
-webkit-transition-delay: 0s, 0.2s; transition-delay: 0s, 0.2s;
<a href="#" id="nav-toggle" class="menu"><span onclick="showmenu('mobile-menu')+clickeffect('nav-toggle')"></span></a>

Answer №1

By clicking, switch the class on .menu to something like active. Afterwards, modify your CSS by replacing .menu:hover with .menu.active

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

Developing JavaScript code for preventing blocking

Managing a large number of file requests from a tiny server has been a challenge for me. With approximately 100 files to fetch, my current approach using JavaScript's forEach loop is causing the server to crash due to the heavy load. links.forEach ...

Unforeseen Issues Arising from Media Queries

Trying out some new styling for different screen sizes based on the bootstrap grid system dimensions. Facing an issue where only certain styles apply while others don't seem to take effect. Here's a snippet of the CSS: @media only screen and ( ...

Troubleshooting Key Press Issues with Bootstrap 5 Dropdown and Collapse Feature

Exploration In my quest to create a dynamic Bootstrap (5) Navigation bar/menu with animated sub-menus, I stumbled upon a solution that seems to fit the bill perfectly. By employing data-bs-toggle="collapse" instead of 'dropdown', I dis ...

Is there any method to transfer the value from form1 to form2 prior to submitting form2?

I am facing a challenge with two forms on a single page. Is there a way to retrieve the selected value from form1 before submitting form2? This will allow me to insert both values (selected value from form1 and input box value from form2) into a table as a ...

Having trouble routing with express and mongoose, constantly encountering the error message "Type Error: req.params.user is not a function"

I have been struggling with a routing issue for days and cannot seem to figure out where I am going wrong. My goal is to add some fields to the users object through a form. Below is my mongoose schema: var userSchema = mongoose.Schema({ local ...

Update the text inside a paragraph using jQuery

When attempting to modify two values within a paragraph using jQuery, I encountered an issue where only one value was successfully updated, leaving the other empty. <div class="container"> <p class="lead custom_bg" id="comment"> updateme! ...

Using Linq to Transform Rows into Columns

I have a table that looks like this: ID Attributes Value 1 Name Jason 2 Age 14 3 Address 12 Test Road A linq query has been created to select each value based on its ID from p in db.p ...

What is causing compatibility issues between Firefox and the provided CSS code?

I am experiencing an issue with the page layout in FireFox. The widths are not displaying correctly and the upload button does not work. However, I have no problems when using IE or Chrome. I have reviewed the code but cannot find any errors. Here is the ...

Conceal javascript within php

<?php if( isset($_GET['message']) ) { $message = urldecode($_GET['message']); echo "<h2 id='mydivm'>". $message . "</h2>"; ?> <script> setTimeout( function() { ...

Encountering an Error when attempting to read and update with Knex.js

I am attempting to sequentially perform read and update operations. Initially, I retrieve data from the database using the id, then I modify it and aim to update the data in the database as well. However, I encounter an error stating "Unhandled rejection E ...

How to make an element active by default in AngularJS

I have designed a custom tabbed section by utilizing the code below: <div class="row step"> <div class="col-md-4 arrow active" ui-sref-active="active"> <a ui-sref="dashboard.create.key_elements" ui-sref-opts="{ reload: true }"&g ...

JavaScript that is subtle and lacks function parameters

Suppose you have: <div id="data" onclick="handleData(1)">Datum 1</div> and you prefer late binding instead: <div id="data">Datum 1</div> <script> $("#data").click(function() { handleData(1); }) </script&g ...

Getting the ThreeJs OrbitControl import version directly from the CDN

Using threejs from CDN and requiring OrbitControl as well, I encountered an issue with importing both Three and OrbitControl using the latest version 0.148.0: import * as THREE from 'https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__ ...

Should I utilize Next.js API route or communicate directly with Firestore from the client side?

Greetings, I am new to Next.js and have a few queries regarding utilizing Firebase authentication on both the client side and server side. My project is set up with Firebase admin and client SDKs, and I have a signup page where users provide their name, em ...

Can someone tell me the method to retrieve the coordinates of a click using jQuery?

I have a div with an 8x8 grid and I am looking to practice using jQuery. How can I determine which row and column a specific div was clicked on? I attempted to use event.pageX and event.pageY, but these only provide the click coordinates rather than the sp ...

Unable to locate module - relative file path

I'm currently running a test with the following code and encountering an error message: Failed: cannot find module '../page/home_page.js The main page consists of: describe("login to website",function(){ var employeeId; var employee ...

Updating the view in AngularJS with a service to keep users engaged even when they are offline

I'm currently developing an application that requires the ability to detect when a user loses internet connection or is unable to reach the server. Various controllers and services should be able to check and update this status easily. I have successf ...

Displaying an object inside an array based on specific conditions

I have an array called cars that contains various objects. I am looking to add the object with the header 'AUDI' only if the variable audi is true. var audi = false; var cars= [ {header: 'fiat', accessor: row}, {header: 'audi ...

Hover Effect in JavaScript

After thoroughly checking all the duplicates below, I still couldn't quite figure out how to achieve the desired effect. Here are some resources I looked into: make animation hover like transition hover JS hover-like animation Hover animation with js ...

Real-time Property Availability Widget

I need assistance with creating a website for a homeowner who wants to rent out their property. The client requires a feature that allows them to log in and easily mark individual days as available or unavailable for rental by choosing specific colors for ...