The button effortlessly transforms into a sleek email submission form

I have a button that is already styled with basic CSS properties for active and hover states. I would like to add functionality so that when the "Join the Loop" button is clicked, it transforms into a simple email form similar to the one found at

Apologies for the vague explanation. You can view my code here: https://jsfiddle.net/hkr95odp/1/

.up {
  opacity: 0;
  background-color:#FFF;
  -moz-border-radius:10px;
  -webkit-border-radius:10px;
  border-radius:5px;
  border:2px solid #ff0000;
  display:inline-block;
  cursor:pointer;
  color:#ff0000;
  font-family:Quicksand;
  font-size:20px;
  padding:10px 10px;
  text-decoration:none;
  margin-right: 30px;
  margin-top: 20px;
  transition: all 0.5s;
  box-shadow: 0px 0px 130px -18px #ff0000;

}
.up:hover {
   background-color: #ff0000;
   color: #fff;
}
.up:active {

}

Answer №1

To improve readability, start by enclosing the signup and signin anchors within span elements. Assign an id to the signup anchor for animation purposes, and immediately follow it with a initially hidden form.

<body>
<header class="header">
  <div class="wrap">
   <span id="animationSandbox" style="display: block;"><h1 class="site__title mega">CONCUR</h1></span>
    <span class="beta subhead">Verifiable &#8226; Public &#8226; News</span>
  </div>
</header><!-- /.site__header -->
    <h5 class="credit">-Product of BRIMM-</h5>
  <div class="sign">
   <span id="signupSpan">
     <a id="signup" href="#" class="up">Join the loop</a>
    <form id="joinform" action="??????" class="join" style="display:none;">
      <label for="email" class="subhead">Email</label>
      <input name="email" style="width: 120px;" class="subhead">  
      <input type="submit" value="Send">  
    </form>
</span> 
   <span>
    <a href="#" class="in">SIGN IN</a>
  </span>   
</div>
  <div id="joinformdiv" class="join" style="display:none;border:1px solid red; padding: 10px;position:absolute;">
  </div>
</body>

Revise the CSS to include a new class that mirrors the 'up' class but lacks transition effects. Apply this class to the form so it resembles the button.

.join {
  background-color:#FFF;
  -moz-border-radius:10px;
  -webkit-border-radius:10px;
  border-radius:5px;
  border:2px solid #ff0000;
  color:#ff0000;
  font-family:Quicksand;
  font-size:20px;
  padding:10px 10px;
  padding-bottom:12px;
  text-decoration:none;
  margin-right: 30px;
  margin-top: 20px;
  box-shadow: 0px 0px 130px -18px #ff0000;
}

Next, link the jQuery library and insert the script:

<script type="text/javascript" src="//code.jquery.com/jquery-1.9.1.js">      </script>

$(document).ready(function() {
    $("#signup").on("click", function(e){
      $("#signup").fadeOut(400, function(){
              $("#joinform")
                .css({opacity: 0, display: "inline"}) 
            .animate({opacity: 1},400, function(){ $("#email").focus()})
      })
    })
});

Upon clicking the signup button, it fades out while the previously hidden form becomes visible through opacity adjustments. This prevents pushing content downwards that would occur if using only fadeIn(). The animate() method smoothly transitions the form's opacity to full visibility.

Unlike positioning the email form absolutely over the button, this approach nests the form within the same parent element as the button to prevent issues with scrolling position.

Answer №2

The most straightforward approach would be to swap out the content of a DIV with an INPUT. You can customize the styling from there as needed - this is just a starting point :)

  <div class="sign">
    <a href="#" class="up" onClick="this.parentNode.innerHTML='<input />'">Join the loop</a>
    <a href="#" class="in">SIGN IN</a>
  </div>

If you'd like to see it in action, check out this working example: https://jsfiddle.net/hkr95odp/2/

Warm regards.

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

Crafting visually stunning interfaces with Material UI

I'm a beginner in Material Design and I could use some assistance with the following structure. Can anyone guide me on how to create this? https://i.stack.imgur.com/NpiVz.png I've managed to add a text box, but now I'd like to place a label ...

Testing a function within a React functional component using jest.spyOn with React Testing Library can be accomplished with the following steps:

I'm currently working on a React component and I'm facing an issue with unit testing using React Testing Library. Specifically, I'm having trouble testing the handleClick function of the TestComponent using jest.spyOn(). Can anyone provide s ...

The issue of continuous requests in AngularJS controllers

In my controller, I have a simple function that calculates the number of answers for each question: $scope.countAnswers = function(questionid) { AnswersQueries.getAnswers(questionid, function(answers) { var answersCount = answers.length; return ...

Transforming Image Annotation from Angular 1 to Angular 4: Overcoming Conversion Challenges and Comparing Equivalents from 1.x to 4

After exploring various options, I am still struggling to resolve the conversion error that occurs when trying to convert my Angular 1.x script for image annotation into Angular 4. The equivalent of angular 1.x code in Angular 4 is not readily available. H ...

Alas, an error has occurred with eslint npm. The elusive 404 Not Found reared its head once more when attempting to access the es

I'm currently in the process of organizing my JavaScript code and preparing to transition to TypeScript. I recently set up node.js, npm, and eslint on my Ubuntu 20.04 system. After doing so, I executed npm -init and eslint -init. $ npx eslist util.js ...

JavaScript - The progression of a virtual pet even when the user is offline

Currently, I am utilizing VueJS and MongoDB to develop an interactive virtual pet. Our approach involves storing user data in localStorage for easy access and retrieval. I'm exploring the concept of allowing the virtual pet to evolve autonomously (s ...

Identifying Hashtags with Javascript

I am trying to identify hashtags (#example) in a string using javascript and convert them to <a href='#/tags/example'>example</a> Currently, I have this code: var text = '#hello This is an #example of some text'; text.r ...

Create object keys without relying on any ORM or database management systems like mongoose or mongodb

Exploring a Mongoose Object: recipe = { "ingredients": [ { "_id": "5fc8b729c47c6f38b472078a", "ingredient": { "unit": "ml", "name" ...

Combining two objects retrieved using ngResource in AngularJS

Seeking guidance on merging two objects retrieved using ngressource. Every 5 seconds, I invoke my service to fetch a message and aim to append the new message with the older ones. The JSON message I receive: [ {"age": 0,"id": "my first tweet","name": "H ...

Highcharts 3D Pie Chart with Drilldown Feature

How can I create a 3D Pie Chart with Drilldown effect? I am having trouble understanding how it works. Here is a JsFiddle Demo for a 3D Pie Chart: JsFiddle Demo And here is a JsFiddle Demo for a 2D Pie Chart with Drilldown feature: JsFiddle Demo You can ...

Leveraging the Power of jsPDF in Your Google Apps Scripts

Is it feasible to integrate jsPDF into a Google Apps Script project? I am attempting to create documents using templated HTML, but certain CSS styles like background-color do not translate to PDF when using the getAs() function. Given the limitations of ...

Execute a PHP function using JavaScript/jQuery with AJAX requests

Hello everyone, I am reaching out for assistance with AJAX as I am still quite new to it. Despite the abundance of examples available, I find it challenging to grasp the concept. Specifically, I need help with my validation of a contact form using JavaScri ...

Error in Express.js application: form fields lose their values

I am currently developing a blogging application using Express, EJS and MongoDB. One of the main features is an "Add New Post" form with an addPost() method in the controller; exports.addPost = (req, res, next) => { const errors = validationResult ...

Leveraging next-generation JavaScript (NextJS), incorporate sass-loader for seamless inclusion of variables in each individual

I'm having trouble implementing a custom webpack configuration in my nextjs project. My objective is to automatically import @import "src/styles/variables.scss"; for all scss files in my application. I have successfully set up a webpack con ...

Adaptable positioned picture

I'm trying to figure out how to make a series of positioned images adjust to the window's dimensions. Should the images be relative and the page wrap absolute, or vice versa? I've been experimenting on jsfiddle but can't seem to get it ...

How can you store previously calculated values in a costly recursive function in a React application?

Consider a scenario where there is a recursive callback function like the one shown below: const weightedFactorial = useCallback(n => { if (n === 0) { return 1; } return weight * n * weightedFactorial(n - 1); }, [weight]); Is it possible to ...

Using CSS to position a pair of divs containing text and images side by side

Is there a better approach to creating two divs and two pictures without using negative margins, similar to the example shown here? ...

Increase the dimensions of the jQuery modal confirmation box

I am working on a jQuery confirmation dialog that displays some details for the user. My goal is to have the dialog adjust its dimensions after the user clicks "YES" to show a smaller text like "Please wait...". How can I dynamically change the size of the ...

Importing Vue and Vuex modules from separate files

Recently, I encountered an uncommon issue. I decided to keep my main.js and store.js files separate in a Vue project. In the store.js file, I imported Vuex, set up a new vuex store, and exported it. However, when importing this file into main.js and settin ...

Verifying the existing user in a personalized Ajax form that is used to update a Woocommerce order

Currently, I am developing a form that allows users to update specific order details, such as expenses and the reason for the expense. After updating the order, a JavaScript alert confirms the successful update, and the order's metadata is updated acc ...