Issue with transition on the second attempt

In this code snippet, I have managed to achieve my desired outcome but it seems to only work on the first run. I am not sure why this is happening, so if anyone can help me out that would be greatly appreciated.

Here is a demo of the code in action:

HTML:

<a id="login" href="javascript:void(0);"> Login </a>

CSS:

.User-Login {  
    visibility:hidden;
    position:absolute;
    left:1150px;
    top:90px;
    background:black;
    -webkit-transition:  height 1s ease;
    transition: height 1s ease; 
    overflow:hidden;
    height:10px;
} 
.box-change {   
    height: 250px;  
}
.box-colap {
    height:10px;
}

jQuery:

$(function () {
    $("#login").click(function () {
        var visi = $(".User-Login").css('visibility');
        if (visi == "visible") {
            $(".User-Login").toggleClass("box-colap");

            setTimeout(function () {
                $(".User-Login").css('visibility', 'hidden');
            }, 2000);
        } else {
            $(".User-Login").css('visibility', 'visible');
            $(".User-Login").toggleClass("box-change");
        }
    });
});

Answer №1

Give this a try instead...

$(document).ready(function () {
    $('#login').click(function () {
        if($('.User-Login').is(':hidden') {
             $('.User-Login').slideDown();
        } else {
             $('.User-Login').slideUp();
        }
    });
});

By clicking the login link, it will determine if the login box is hidden or not. If hidden, it will slide down, otherwise it will slide up.

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

Which is the preferable option for creating a circular daily planner: canvas or SVG?

As a novice programmer delving into the world of coding (or at least hoping to), I have a question regarding graphic tools in html5 for my latest project. My goal is to create a planner app using electron, with the unique twist that the planner form sho ...

Executing an Ajax SPARQL request in Firefox

I've been attempting to run an asynchronous Ajax sparql query on dbpedia using Firefox, but I encountered a strange issue that I can't seem to figure out. Surprisingly, the query works perfectly fine in Chrome, Edge, and Internet Explorer, but wh ...

How can I implement a sliding page effect using jQuery with a single navigation bar?

I came across a helpful tutorial at this link: I really admire the sliding effects on this website: Is there a way to achieve similar sliding effects like dk new media's, but with just a single navigation bar? ...

The integration of signalR with jquery mobile is posing several challenges

Recently, I started working with jquery mobile and signalR to implement a calling feature in my mobile app. However, I encountered an error that looks like this: http://localhost:2286/signalr/negotiate?clientProtocol=1.5&connectionData=%5B%7B%22name%2 ...

The input box fails to show larger values on the user's page

Show me the biggest number that the user enters in an input box and then display it back to them. I need some improvements to my code, ideally making it possible with just one input box instead of two. <!DOCTYPE html> <html la ...

jQuery's simple scrolling feature is currently not functioning as intended

Could someone explain why the following code snippet is not functioning correctly? The objective is to smoothly scroll the screen to an anchor destination, taking into account the height of a fixed header with ID "jeden". $(document).ready(function() { ...

Eliminate distinct objects during touchend event in a multi-touch web application

Despite my best efforts and endless searching online, I am struggling to find a solution. While the touchstart and touchmove events allow me to retrieve a unique id from touches.identifier, it seems impossible to achieve this with the touchend event. M ...

Guide on enabling the scrollbar within a text area while utilizing the pointer-events: none property

After applying the CSS rule pointer-events: none to the text area, I noticed that the scrollbar was disabled. I need the scrollbar to remain enabled so that users can scroll and view the entire content, while still preventing editing within the textarea u ...

Centering navigation using HTML5

I've been struggling a bit trying to build a website, particularly with centering my <nav> tag. Despite reading numerous suggestions like using CSS properties such as margin: 0 auto; or text-align: center, nothing seems to be working for me. Si ...

Transfer information to a different division using Ajax

I am attempting to transfer data to another div after an Ajax refresh. Each time it refreshes, new data is fetched from the database. My goal is to retain the old data displayed in the first div, store it, and then move it to the second div when Ajax refre ...

What is the method for obtaining worth?

What is the best way to retrieve the currently selected value from a dropdown inside a specific div? The div's id is "divcontent" and the dropdown's id is "country". Here is an example of the code: <form id="frm1"> It's worth mentio ...

What steps do I need to take to create a basic API that links to a MySQL database?

I'm currently trying to develop an API for PHP that will enable one web server to communicate with another web server. Additionally, I want this API to be able to update MySQL code. Previously, I was utilizing $_GET parameters for this purpose but rea ...

Chrome and Safari browsers are both experiencing a glitch where the Full Calendar event time is automatically adding an

Currently, I am utilizing Jquery fullcalendar 3.3.1 and moment.js 2.15.1 to display an event calendar. When clicking on an event, a modal popup showing the event details appears. The event details are stored in an SQL database, and ajax is used to populate ...

In what format is the parameter accepted by the .getDay() method?

Here's the plan: I need to extract information from an input element with type set as date. This data will then be stored in a .json file and later parsed when the program is initiated. Subsequently, I aim to utilize the date.getDay() function to dete ...

jQuery form validation not functioning as expected

I'm attempting jQuery form validation but encountering issues with the desired functionality. I would like the border of an input to turn red when it's empty upon focus out. Alternatively, I aim to incorporate the "has-danger" bootstrap class to ...

Using jQuery to enhance an HTML form

Currently, I am in the process of creating an HTML form for user sign up which includes typical fields such as username, password, and email. My intention is to transfer the entire HTML form to another .php file using the POST method. The second .php file ...

The top margin in CSS relative positioning is not being displayed

My client has a specific requirement for the webpage to be positioned in the center of the screen. To achieve this, I have enclosed the entire webpage within a div element called "mainpage". Here is the CSS code: #mainpage { position:relative; wi ...

Tips for creating a responsive HTML5 form

I am trying to center and make my form responsive. Can you help me achieve that with the code below? HTML5 Code <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html ...

JavaScript: Filtering list by elements that contain a certain value

I have the following collection of objects: [ { employeeId:1 employeeName:"ABC" }, { employeeId:2 employeeName:"ABD" }, { employeeId:3 employeeName:"FEW" }, { employeeId:4 employeeName:"JKABL" },] I am looki ...

To modify the background of a text, simply click on the image

I recently discovered a helpful hack in an answer on this website, which allows an image to be resized when clicked using the checkbox method. I have successfully implemented this feature but encountered an issue when trying to apply a CSS style change to ...