"Enable a smooth transition and switch the visibility of a div element when clicked

How to create a dropdown form with a transition effect that triggers on click of an element? Once triggered, the transition works smoothly but clicking again only hides the div element without triggering the transition. See the demo here:

Check out the function below:

JavaScript snippet:

<script>

$(function() {

    $("#login").click(function() {
        var visibility = $(".User-Login").css('visibility');

        if(visibility == "visible") {
            $(".User-Login").toggleClass("box-colap");
            $(".User-Login").css('visibility', 'hidden');    
        }
        else {
            $(".User-Login").css('visibility', 'visible');
            $(".User-Login").toggleClass("box-change"); 
        }       
    });
});

HTML structure:

<table class="MainMenu" style="width:100%;background-color:white" align="center">
<a href="#">Home</a>
        &nbsp;
        &nbsp;
        </td>
        <td>
        <a href="#">How It Works </a>
        </td>
        <td>
        <a href="#"> Features</a>
        </td>
        <td>
        <a href="#"> Why Us </a>
        </td>
        <td>
        <a href="#"> Sign Up </a>
        </td>
        <td>
        <a id="login" href="javascript:void(0);"> Login </a>
        </td>
</table>

CSS styles:

.User-Login {  
    visibility: hidden;
    position: absolute;
    left: 1150px;    
    background: black;
    -webkit-transition: height 2s ease;  
    -moz-transition: height 2s ease;  
    -o-transition: height 2s ease;  
    -ms-transition: height 2s ease;  
    transition: height 2s ease;  
    overflow: hidden;
    height: 10px;
    top: 90px;
}  

.box-change {   
    height: 250px;  
}

.box-colap {
    height: 10px;
}

Answer №1

Discover two easy CSS3 solutions that don't require jQuery

Check out fiddle 1 here

Or view fiddle 2 for more examples

Both examples utilize the power of CSS3 for animation effects

Here is the necessary CSS code to create sliding animations:

div{
display:block;
height:120px;
width:120px;
background:red;
}

.hideUp{
    position:relative;
    height:200px;
    width:200px;
    background:blue;
    display:block;
    -webkit-transition:all 1s ease;
    -moz-transition:all 1s ease;
}

.hideUp:focus{
    top:-200px;
}

Below is the corresponding HTML code:

<a href="#" tabindex="-1" class="hideUp"><div><p>CLICK TO MOVE</p></div></a>

:)

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

The chat text will automatically scroll down, displaying information loaded from the database

Is there a way to ensure that chat text always remains scrolled to the bottom of the chat? I have tried multiple tutorials and examples from Stack Overflow, but none seem to work for me. Currently, my chat text overflows the textarea when there are too m ...

Perform Action Only When Clicking "X" Button on JQuery Dialog

I have a dialog box with two buttons, "Yes" and "No", which trigger different functions when clicked. $('#divDialog').dialog({ modal:true, width:450, resizable: false, buttons: [{ text: 'Yes', ...

What's the trick to efficiently managing multiple checkboxes in an array state?

I have a lengthy collection of checkboxes that is not well optimized. I am trying to obtain the checked ones and store them in an array state. However, I am uncertain about how to handle this situation and I would appreciate some assistance. It should also ...

Troubust with multiple levels in jQuery accordion

I'm having some trouble building the jQuery accordion. It's working fine on the first level, but not on sub-levels. Can anyone provide assistance in fixing this issue? Here is the fiddle link for reference. Below is the code snippet: $(documen ...

Incorrect positioning on canvas

Is there a way to adjust text alignment within a canvas? Currently, my text is centered. However, when I change the text size, the alignment gets thrown off. Here is the code snippet: <canvas id="puzzle" width="480" height="480"></canvas> ...

How can I emphasize the React Material UI TextField "Cell" within a React Material UI Table?

Currently, I am working on a project using React Material UI along with TypeScript. In one part of the application, there is a Material UI Table that includes a column of Material TextFields in each row. The goal is to highlight the entire table cell when ...

Tips for reducing code length in jQuery

Here's an interesting question that I've been pondering. Is there a more efficient way to optimize and condense code like the one below? Could it be achieved using functions or loops instead of having lengthy jQuery code? var panels = ["panel1", ...

Having issues with AngularJS where ng-table/ng-repeat rows are failing to load properly

I've been following a tutorial on using ng-Table, which can be found Here. When I download the example from Git, it loads without any issues. However, when I try to replicate even the simplest example myself, the column headers and filters load but th ...

Error encountered during Atom execution - The command '/usr/bin/env: 'node' was not found in the directory

Just starting out with coding on Atom and I'm stuck dealing with the same error message every time I try to run my Javascript code. bash: line 1: node: command not found /usr/bin/env: ‘node’: No such file or directory I've searched for solu ...

Listening for Events from Child Components in Vue.js

I am struggling to figure out how to send an event from a child component to its parent in order to change the view. Although I have been able to create and emit the event, my template does not seem to be properly registering it. I am working with Single ...

Ways to ensure your page stays confidential

Concept: Exploring the idea of making specific pages on a website private. For example, having 4 navigation links where one link leads to a private page that requires a username and password for access. Currently, my practice website has 7 links directing ...

Asynchronous AJAX request using JQuery loader with async:false setting

As a newbie to the world of jQuery, I find myself lost in solving my current issue. Despite checking various solutions to similar problems, none seem to work for me. Working on MAC OS X using Safari with JQuery 2.1.1, I must ensure that my platform is comp ...

Discover the content of meta tags using Python and Beautiful Soup

I am attempting to extract the meta data from a specific website, as shown in the code below. import requests from bs4 import BeautifulSoup source = requests.get('https://www.svpboston.com/').text soup = BeautifulSoup(source, features="html.par ...

Getting rid of quotes in a JSON result

My unique code snippet Retrieve data = Array[2] : 0:object id : "1" lat : "76.23" long:"21.92" 1:object id:"2" lat:"10.23" long:"12.92" var newCoords=[]; for(_i = 0; _i < ...

Count characters in multiple text inputs with AngularJS

Currently, I am developing an Angular JS application with the help of Angular-UI (bootstrap). In this app, there are multiple input boxes where users can enter data, which is then displayed in a div. My goal is to have a character count that applies to al ...

Centering items in Material UI Grid

I'm currently grappling with understanding Material UI's grid system and implementing it in React.js, and I find it a bit perplexing. My goal is to center the spinner loader and text irrespective of viewport size. While I can manage to place the ...

PassportJS ensuring secure authentication across all routes

Currently, I am implementing passportJS to secure my API Endpoints within an Express application. So far, the following code is functioning properly. app.get("/route1", passport.authenticate('basic', { session: false }), (req, res) => { ...

Incorporating a variety of classes by utilizing loops

Looking to add a class to specific li elements - the 1st, 4th, and 7th, the 2nd, 5th, and 8th, and the 3rd, 6th, and 9th. Is this possible? Is there a way to achieve this? ...

Could you explain the distinction between these two arrow functions?

I'm puzzled about why the second arrow function is effective while the first one isn't. //the first one doesn't function properly this.setState = () => { text: e.target.value, }; //in contrast, this one ...

Updating Select Options Disabled/Enabled in Angular 2

In my Angular2 project, I have 2 select elements: <div ng-controller="ExampleController"> <form name="myForm"> <label for="companySelect"> Company: </label> <select name="companySelect" id= ...