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

Adapting CSS grid columns based on device screen size

I am currently experimenting with CSS grid to create a layout that changes based on different screen sizes. Here is what I want to achieve: On a mobile screen, there should be one column that takes up the entire width. This column consists of two sections ...

What is the best way to update information within a <tbody> tag?

Can someone assist me with replacing content in an HTML table? Please review my code below: <html> <head> <script type="text/javascript"> function changeRows() { var htmlString="<tr><td>bhanu</td><t ...

prettyPhoto popup exceeds maximum width and height limitations

I am currently using the most up-to-date version from No Margin for Errors and I have set allow_resize to true. However, the size of the display is still too large. Is there a way to set a maximum width/height? I have already configured the viewport as fo ...

Alignment and spacing in a flexible direction

Hello, I am developing a bar app. <AppBar position="sticky" className={classes.appBar} > <Container maxWidth="lg"> <Toolbar className={classes.root}> <Typography noWrap> <img src={require("./node ...

The Ajax request fails to set a value within the done callback

Here is a function I have: var isNameUnique = false; function ValidateName() { var url = "/SomeRules/CheckIfNameExists/"; var request = $.ajax({ url: url, method: "GET", data: { sName: name}, ...

Container for grid template columns and responsive window in a single row

Imagine having around 250 divs with the class slider-item styled in a certain way. You have a responsive grid in CSS called A which arranges these divs as columns/items when the window resizes, with a minimum item width of 240px. Check out how it looks bel ...

When I click on a specific div, another div should be appended to the main_div

I am just starting to learn about jquery and have a simple application where I need its functionality. Within my layout, there are several small divs on the left side (such as div1, div2...), and one main div in the center of the page. My goal is to have ...

Repeatedly view the identical file on HTML

I'm currently working with the following HTML code: <input type="file" style="display: none" #file(change)="processImage($event)" /> <button type="button" class="btn" (click)="file.click()" Browse </button> When I select image1 fr ...

Why aren't CSS media queries functioning in the existing stylesheet?

I have a good grasp on responsive design and CSS techniques. However, I am encountering an issue where the media query for mobile dimensions is not working as expected. When monitoring the applied styles in Chrome, only the min-device-width styles are be ...

Tips for entering Tamil characters in text boxes on a form field

Within my form, I have a set of text boxes. I am looking to input text in Tamil font for specific text boxes - around 5 out of the total 10 text boxes in the form. If you know how to enable Tamil font input for multiple text boxes (rather than just one as ...

Is the [] value always populated in the second DropDownList?

After populating two DropDownList in my View, I encountered an issue with the values not updating as expected: <tr> <td class="info_label">City</td> <td>@Html.DropDownListFor(m=>m.User.City,Model.City,"-- Select ...

Dealing with challenges in integrating ngx-masonry with Angular 14

I am currently working with Angular 14 framework and the ngx-masonry library (https://www.npmjs.com/package/ngx-masonry/v/14.0.1). However, I am facing some issues where it is not functioning correctly. I would appreciate any assistance or guidance on how ...

Choose a specific name from the object

Currently, I am in the process of learning and would appreciate your patience. I have a json response from which I need to extract specific elements. My goal is to identify particular elements within an object by their name, such as "length" or "width", an ...

Using brush strokes to create a unique design on the canvas page

Currently, I am working on implementing a brush-like effect on a web page. The task involves providing multiple patterns/textures in the background and allowing users to drag their mouse to create the pattern effect on the page. If you want to see the st ...

The issue of duplicate CSS arising during the compilation of SASS into a single CSS file with G

Just getting started with Stack Overflow and Gulp (using version 3.9.1). My goal is to compile all of my scss files into a single css file for my website. Here's what I have in my gulpfile so far: var gulp = require('gulp'); var sass = requ ...

The HTML navbar seems to have a mind of its own, disappearing and shifting around unpredictably as I zoom in or resize

WHEN DISPLAYING THIS CODE, IT IS ADVISED TO VIEW IN FULL PAGE MODE This code includes navigation, header, and styling elements. However, when the browser is zoomed in or out, the navbar tends to move around and eventually disappears off the screen if wind ...

How can you use mouseover events to display a popover and manipulate the div id?

In my scenario, I have multiple div elements and I want to display separate popover for each div. Initially, the popover is not shown on the first mouseover event but works perfectly on subsequent attempts. Below is the code snippet: $(document).read ...

Reverting Changes Made with JQuery Append

I have a table where each cell contains a button. When the button is pressed, it adds text to the cell. I am looking for a way to remove this text from the cell when the same button is pressed again. It's important to note that this button appears mul ...

Dynamic drop-down navigation with rearranging menu

I am attempting to design a drop-down navigation bar with 2 rows. Initially, only 1 row is visible. Upon clicking the visible row, both rows should appear. Subsequently, when one of the 2 rows is clicked, only that specific row should be displayed. Below a ...

Exploring the challenges of applying styles to buttons using the :first-child and :last-child selectors, especially when

I successfully applied rounded corners to the first and last elements of a styled button using CSS. Here is how it looks: The issue arises when I dynamically insert new buttons using Angular's ng-if. The new buttons disrupt the rounded corners of th ...