What is the best way to have a form open upwards when hovered over or clicked on?

Attempting to create a button in the bottom right corner that will reveal a form when clicked or hovered over. The form should slide open slowly and close after clicking on login, but currently the button is moving down as the form opens.

The button also needs to be positioned on the right side. Tried using float:right; and right:0; to no avail.

Below is the code snippet:

function showForm(){
  document.getElementById('loginForm').style.display = "block";
}

function hideForm(){
  document.getElementById('loginForm').style.display = "none";
}
*{
  margin: 0;
  padding: 0;
  box-sizing: border-box
}
  .no-show{display:none;}
  .form-container {
  position:absolute;
  bottom:0;
  right:0;
  float: right;
  width:100%;
}
body { font-family: tahoma; }
#loginForm  {
display: none;
background: #ccc;
width: 250px;
height: 100px;
padding: 20px;
color: #333;
}
.label {
   cursor: pointer;
   display:block;
   padding: 5px 15px;
   font-size: 16px;
   font-weight: bold;    
}
.form-label {
width: 70px;
font-size: 12px;
font-weight: bold;
}
.form-field {
width: 180px;
}

.form-elements {
font-size: 0px;
margin: 10px 0 0 0;
display: block;
}

.form-label, .form-field {
display: inline-block;
}

.form-field input {
padding: 3px 5px;
}

.submit-btn input {
margin-left: 70px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="form-container">
<form>
  <p id="login" onmouseover="showForm();" onmouseout="hideForm();">
<span class="label">Login</span>  
<span id="loginForm">        
  <span class="form-elements">
    <span class="form-label">Name:</span>
    <span class="form-field"><input type="name" /></span>
  </span>        
  <span class="form-elements">
    <span class="form-label">Password:</span>
    <span class="form-field"><input type="password" /></span>
  </span>
</span>      
  </p>
</form>
</div>

Check out the live demo here - https://jsfiddle.net/d5L8bywk/1/

The form should smoothly open upwards and close upon clicking the login button.

It should resemble this design: https://i.sstatic.net/cXpcw.png

Answer №1

Take a look at this code snippet. You don't need jQuery for this functionality, you can accomplish it using pure CSS transitions in combination with the height property.

function displayForm() {
  document.getElementById('loginForm').classList.add('show');
}

function hideForm() {
  document.getElementById('loginForm').classList.remove('show');
}
*{
  margin: 0;
  padding: 0;
  box-sizing: border-box
}

body {
  font-family: tahoma;
  height: 100vh;
}

.no-show{
  display:none;
}

.form-container {
  position: absolute;
  bottom: 40px;
  right: 80px;
  left: auto;
  top: auto;
  width: 230px;
}

#loginForm  {
  background: #ccc;
  width: 250px;
  color: #333;
  height: 0;
  overflow: hidden;
  transition: all 0.5s;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

#loginForm.show {
  height: 150px;
}

.label {
  cursor: pointer;
  display:block;
  padding: 5px 15px;
  font-size: 16px;
  font-weight: bold;
}
.form-label {
  width: 70px;
  font-size: 12px;
  font-weight: bold;
}
.form-field {
  width: 180px;
}

.form-elements {
  font-size: 0px;
  margin-bottom: 10px;
  display: flex;
  flex-direction: column;
}

.form-label, .form-field {
  display: inline-block;
  width: 100%;
}

.form-field input {
  padding: 3px 5px;
}

.submit-btn input {
  margin-left: 70px;
}

#login {
  text-align: center;
  cursor: pointer;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <div class="form-container">
<form>
    <div id="loginForm" onmouseleave="hideForm();">
      <span class="form-elements">
        <span class="form-label">Name:</span>
        <span class="form-field"><input type="name" /></span>
      </span>
      <span class="form-elements">
        <span class="form-label">Password:</span>
        <span class="form-field"><input type="password" /></span>
      </span>
    </div>
</form>

<span id="login" class="label" onmouseover="displayForm();">Login</span>
  </div>

Answer №2

#login{
float:right 
}

<div class="form-container">
  <form>
<p id="login" onmouseover="showForm();" onmouseout="hideForm()">

  <span id="loginForm">        
      <span class="form-elements">
        <span class="form-label">Full Name:</span>
        <span class="form-field"><input type="name"></span>
      </span>
      <span class="form-elements">
        <span class="form-label">Password:</span>
        <span class="form-field"><input type="password"></span>
      </span>
  </span>
   <span class="label">Sign In</span></p>
 </form>
</div>

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

Discover the myriad of possibilities created by combining arrays

I am working on a code snippet that aims to generate an array containing all possible combinations between two or more arrays. However, I am encountering a specific issue. getCombn(arr: string | any[], pre?: string | undefined) { pre = pre || ' &a ...

Using Vue3 to create a dynamic reference in a computed status, allowing for the repetition of a player multiple times in a table along with a play/pause

On the Vue3 page below, I have successfully integrated a player that displays a "play" icon when the player is stopped and a "pause" icon when it's playing. Now, my goal is to allow the player to repeat n times by placing it in a table. The challeng ...

What methods can be used to configure Jasmine to read individual Vue component files?

I recently installed Jasmine and Vue through npm, but I'm encountering an issue when trying to import the Vue component itself, which is a .vue file. It seems to be having trouble reading the template section enclosed within <template></templ ...

Navigate to a different page in Vue3 after completing the file download process

After receiving a link from the server to download the file, the user initiates the function to begin downloading. Once the file has finished downloading, the user will be redirected to the main page. <script setup lang="ts"> const goToMai ...

Ensure that it is safe to bypass Vue's built-in sanitization on this specific Vue component for the href attribute

I encountered an issue with a .vue file that contains an anchor tag as shown below: <a class="login_class" :href="loginUrl">Use Universal Login</a> When running Sonar, it raises a warning regarding the :href attribute: En ...

Difficulties arise when dealing with card elements and scrolling on a

Currently working on an ecommerce simulation project for a course, I successfully implemented a featured section with cards. However, when it comes to scrolling, I am facing an issue where the cards overlap with my sticky navbar as I scroll down. If anyo ...

Jumping Iframe Anchor Link in Src

I'm facing a challenge with an iframe positioned in the center of a webpage. I want to show content from another page within the iframe, but not starting at the very top. To achieve this, I inserted an anchor into the src of my iframe, linked to an a ...

Swapping out data points using JQuery

What could be causing line 10 to return null? Click here for the code file The code seems to function properly with line 40, but not with line 10. ...

What steps should I take to create a functional image scrolling effect similar to the one shown in this example?

Recently, I came across and was intrigued by the "image slide effect" featured on their homepage. The way the background image changes as you scroll up, leading you through different introductory slides before reaching the main content of the site caught ...

Customize your file input with Bootstrap 4 using bs-custom-file-input and create a Symfony 5 collection with dynamic upload fields

The issue of not having a label for the chosen filename in a bootstrap 4 upload field has been resolved using the plugin https://github.com/Johann-S/bs-custom-file-input You can utilize "bs-custom-file-input" to showcase the selected filename in the boots ...

Easy way to eliminate empty elements following a class using jQuery

I'm encountering a situation where I have a group of elements following a specific class that are either empty or contain only white space. <div class="post-content"> <div class="slider-1-smart"> --- slider contents --- < ...

Transforming a jQuery menu into an active selection with Vue JS

I am looking to transition away from using jQuery and instead utilize Vue for the front end of a menu. Specifically, I need to add an active class and a 'menu-open' state to the appropriate nested list items, similar to what is achieved in the pr ...

What is the best way to access the tooltip text in Reddit?

Currently, I am in the process of developing a Selenium web scraping tool specifically for Reddit. However, I am encountering some challenges in extracting the timestamp displayed in the image. from selenium import webdriver from webdriver_manager.chrome i ...

Creating a 404 Error Response in Express.js

Inside app.js, I currently have the following code: // catch 404 and forward to error handler app.use(function(req, res, next) { var err = new Error('Not Found'); err.status = 404; next(err); }); This code executes when a non-existent URL ...

My applications are not firing the deviceready event as expected

Struggling to incorporate a cordova plugin into my vue.js project using vue-cordova. Specifically, I am attempting to utilize the open-native-settings plugin to access device settings on iOS or Android. While it works seamlessly in the demo app provided b ...

Error message received while converting webm video to images using Kagami/ffmpeg.js: Unable to locate an appropriate output format for '%04d.jpg'

These are the current versions: node v12.9.1, npm 6.10.2, [email protected] Repository: https://github.com/Kagami/ffmpeg.js The code in decode.js looks like this: const fs = require('fs'); const ffmpeg = require('ffmpeg.js'); c ...

Creating a <Box /> component in MaterialUI with styled components is a great way to customize the design and layout of your

@material-ui/styles offers a different way to customize default styles: import React from 'react'; import Box from '@material-ui/core/Box'; import { styled } from '@material-ui/core/styles'; const StyledBox = styled(Box)({ ...

Choosing two distinct options and transmitting information to PHP via AJAX

I'm encountering an issue where I am trying to pass two different values from select options using AJAX, but PHP seems to be not responding to the request. Below is the jQuery code I am using: $(document).ready(function() { $("#updateStatus").chan ...

The Bootstrap carousel spiraled into disarray

I am facing an issue with the basic bootstrap carousel. My goal is to make the slides move every four seconds. The current setup of the carousel code is as follows: $(document).ready(function() { fixCarousel(); }); function fixCarousel() { $('.c ...

Generate a hyperlink within a paragraph

Can anyone provide tips on how to turn a string from Json into a paragraph with a hyperlink included? <p>Dumy Dumy Dumy Dumy Dumy Dumy Dumy DumyDumyDumyDumy abc.com </p> Currently, the paragraph displays as is, but I would like to make abc.c ...