Tips for effectively utilizing an if/else structure to animate fresh content from the right while smoothly removing old content by sliding it to the left

document.getElementById("button1").addEventListener("click", mouseOver1);

function mouseOver1(){

   document.getElementById("button1").style.color = "red";

}


document.getElementById("button2").addEventListener("click", mouseOver); 


    function mouseOver(){ 

      document.getElementById("button2").style.color = "purple";
   }



$("#button1").hover(function() {
    $(this).css('cursor','pointer');
}); 

$("#button2").hover(function() {
    $(this).css('cursor','pointer');
});

   if($(".existing1-username-input-textbox").get(0).val()== "Micheal22" && $(".existing2-password-input-textbox").get(0).val()== "honor7thG")  
 {
        $('#button1').on('click', function () {
        $('.username-label').animate({'left': '-105%'}); 
        // but I want all the old content to slide to the left if username and password match above
        // then new content should slide in from the right. 

        });  
  
  }else{
  $(".existing1-username-input-textbox").firstChild.nodeValue="The existing username is not correct";
 
  $(".password-new-input-textbox").firstChild.nodeValue="The existing password is not correct"; 

  }
          
.intro h1 {
  font-family: 'Cambria';
  font-size: 16pt;
  font: bold;
  text-align: left;
}

.intro p {
  font-family: 'Calibri';
  font: italic;
  font-size: 12pt;
  padding: 0px 690px 0px 20px;
  text-align: left;
}

.content {
  border: 2px solid;
  -webkit-border-radius: 10px;
  -moz-border-radius: 10px;
  border-radius: 10px;
}

#para1 {
  padding: 0px 1050px 0px 20px;
}

#para2 {
  padding: 0px 1099px 0px 20px;
}

.username-label,
.password-label {
 margin: 10px 0px 0px 300px;
 position: relative; 
 top: -70px; 
}

.existing1-username-input-textbox, 
.existing2-password-input-textbox
{
    top: -70px; 
     position: relative; 
      
}

#button1{ 
     background-color: #add8e6;
     margin-left: 390px; 
     position: relative; 
     top: -50px; 
    -webkit-border-radius: 10px;
  -moz-border-radius: 10px;
  border-radius:10px;
  padding: 0px 20px 0px 20px; 
}

#button2{
  background-color: #add8e6;
  margin-left: -200px; 
  position: relative; 
  top: -30px; 
 -webkit-border-radius: 10px;
  -moz-border-radius: 10px;
  border-radius: 10px;
  padding: 0px 20px 0px 20px; 

}


.Username-label1, 
.Password-label2,           
.Email-label3, 
.Repeat-Email-label4 
{
  margin: 0px 0px 0px 300px;
  position: relative; 
  top: -70px; 
}
.username-new-input-textbox, 
.password-new-input-textbox, 
.email-new-input-textbox, 
.reenter-new-input-textbox{ 
  position: relative;
   top: -70px;
  margin-left: 20px; 

}
<html>

<head>

  <link href="Home.css" rel="stylesheet" />
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
  <title>Project</title>

</head>

<body>


<div class="container">
  <div class="intro">

    <h1>Welcome to Cuyahoga Community College Student Services Online</h1>

    <p>Cuyahoga Community College recognizes students' rights to access personal and academic records in accordance with the Family Educational Rights and Privacy Act of 1974 (FERPA) as amended by Public Law 93-568.</p>
  </div>
  <br/>

  <div class="content">
    <div class="row top">
      <p id="para1">Already have an account with us? Returning users may log in by entering their site username and password. </p>
      <div class="login">
        <label class="username-label" for="username-part1">Username</label> &nbsp; 
         <input class="existing1-username-input-textbox" type="text" value="" />
        <br/><br/>
        <label class="password-label" for="password-part2">Password</label> &nbsp; 
        <input class="existing2-password-input-textbox" type="password" value="" />
        <br/>
        <button id="button1">Log in</button>
      </div>
    </div>
    <hr/>
    <div class="row bottom">
      <p id="para2">New users, please create a new account by providing us with some basic information.</p>

      <div class= "new_customers_info">

        <label class="Username-label1" for="new-user-name-part-1">Username</label>
        <input class="username-new-input-textbox" type="text" value="" />
         <br/><br/>

        <label class="Password-label2" for="password-new-part2">Password</label>
        <input class="password-new-input-textbox" type="password" value="" />
         <br/><br/>

        <label class="Email-label3" for="email-new">Email Address</label>
         <input class="email-new-input-textbox" type="text" value=""/>
          <br/><br/>

        <label class="Repeat-Email-label4" for="repeat-new-email">Repeat Email Address</label>
         <input class="reenter-new-input-textbox" type="text" value="" />

        <button id="button2">Create Account</button>
      </div>
    </div>
  </div>
   <br/>
  <footer>Cuyahoga Community College</footer>
  <footer>700 Carnegie Avenue, Cleveland, Ohio, 44115</footer>
</div>
    <script src="Home.js"></script>
</body>
</html>

Is it possible to implement a slide effect for transitioning the content from left to right upon clicking button 1 if the existing student's username and password are valid? If not, I want to display error messages below the respective textboxes. How would I manage the existing account information to be displayed upon sliding it from the right, especially if the content isn't created yet? When the new content is ready to be displayed, where should I store this information until it's needed? Here is my current code.

Answer №1

When the page is loaded, the following code will be executed. At that moment, the username and password fields will be blank, so no event will be associated with the login button:

if($(".existing1-username-input-textbox").get(0).val()== "Micheal22" && $(".existing2-password-input-textbox").get(0).val()== "honor7thG")  
{
    $('#button1').on('click', function () {
        $('.username-label').animate({'left': '-105%'}); 
        // but I want all the old content to slide to the left if username and password match above
        // then new content should slide in from the right. 

    });    
}else{
    $(".existing1-username-input-textbox").firstChild.nodeValue="The existing username is not correct";
    $(".password-new-input-textbox").firstChild.nodeValue="The existing password is not correct"; 
}

It is recommended to change the code to the following:

$('#button1').on('click', function () {
    if($(".existing1-username-input-textbox").get(0).value== "Micheal22" && $(".existing2-password-input-textbox").get(0).value== "honor7thG")  
    {
        $('.username-label').animate({'left': '-105%'}); 
        // but I want all the old content to slide to the left if username and password match above
        // then new content should slide in from the right. 
    }else{
        $(".existing1-username-input-textbox").firstChild.nodeValue="The existing username is not correct";
        $(".password-new-input-textbox").firstChild.nodeValue="The existing password is not correct"; 
    }
});    

After this change, the click event will be associated with the login button on page load. Therefore, when you click login, it will first check the username and password. If they match, the animation part will take effect. Otherwise, the else part will be executed.

Answer №2

If you're looking for a quick solution, consider using JQuery's .animate function.

Take a look at this code snippet for an example: http://jsfiddle.net/f7VdQ/135/

$(function () {
    $('a').on('click', function () {
        $('.left').animate({'left': '-105%'});
        $('.right').animate({'left': '0px'});
    });

    $('p').on('click', function () {
        $('.left').animate({'left': '10'});
        $('.right').animate({'left': '105%'});
    });
})

PS.: To prevent overlaying of content (an additional functionality in the fiddle), avoid using z-indexes in the CSS and opt for relative positioning.

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

Encountering an issue while trying to import the instanceMethods function within Sequelize

In a file, I have written a function and exported it like this: export function foo(params...) { // do something } When initializing the model, I imported the function in the following manner: import { foo } from "../path/..." instanceMethods: { foo ...

Why are the UI components (`Card Number`, `MM/YY`, `CVC`) not being displayed in the React app when using Card

Having an issue where the CardElement Ui component is not visible in the image provided. It should appear above the Order Total: $0 next to the payment method. https://i.sstatic.net/NCK5z.png I've attempted various debugging methods without success. ...

Encountering a problem with Firebase while offline. The error message "FirebaseError: Firebase App named '[DEFAULT]' already exists with different options or config." is appearing

I've been having some trouble integrating Firebase into my app using the useFireBaseAuth hook. Everything works smoothly when there's an active internet connection, but I'm facing issues when offline. An error message shows up: Server Error ...

The horizontal scrolling with overflow-x is not functioning correctly as it is displaying the scrollbar for the vertical

I am perplexed as to why I am unable to scroll horizontally to view the other pink thumbs. Despite adding an overflow of scroll-x to the thumbs container, which should theoretically allow horizontal scrolling, it only seems to scroll vertically. Could som ...

React Bootstrap's drop-down components with a dark theme

In my react application, I am looking to design a custom navbar for the header using react-bootstrap. Specifically, I need a dark styled NavDropdown that changes background color to #f0ad4e on hover. Despite attempting the following code snippet, I couldn& ...

The Enigmatic Essence of TypeScript

I recently conducted a test using the TypeScript code below. When I ran console.log(this.userList);, the output remained the same both times. Is there something incorrect in my code? import { Component } from '@angular/core'; @Component({ sel ...

Unable to iterate through nested arrays in Contentful mapping

I am facing an issue while trying to map further into the array after successfully retrieving data from Contentful. The error message field.fields.map is not a function keeps popping up and I can't figure out what I'm doing wrong. export defau ...

What is the best way to determine if a property exclusively belongs to the child class or its subclass in Javascript?

I am currently working on a project in Javascript where I need to retrieve properties that are only present in a subclass (child class) and not in the parent class. Despite using .hasOwnProperty(), I have run into an issue where it also returns true for th ...

Learn how to easily modify a value in a CVS file by simply clicking on the data point on a highcharts graph

Is there a way to update my CSV file by clicking on a graph? I want to be able to create a graph from data in the same CSV file and then, when I click on a point, set that point to zero on the y-axis and update the corresponding value in the CSV file to 0. ...

Hovering over an image with CSS for a cool effect - altering the background and text

I'm experimenting with creating a mouseover effect on images where the background becomes dimmer and text appears on top. For example, you can take a look at this page and scroll down to see how the second set of images darken and display text when y ...

D3 and dimple line graphs

As I continue to explore D3, I am working on a project where I need to display data using the Dimple module for charting. The user should also have the ability to add parameters. I have experimented with two different ways of formatting my data, and I hav ...

Is there a way to update a field or submit a form without having to redirect or refresh the page?

I am struggling to find the right solution for updating just one field in my database called Flag, which is a Boolean field. I have tried using ajax/JQuery, but it only works for the first item in the list and stops working for subsequent items. The ID and ...

Guide on how to retrieve and log a list of objects from a map using Puppeteer, based on elementsArray obtained through the use

I'm working on a Puppeteer script that is supposed to log a list of generated objects using the map method. const getFilteredOrders = async (page, pagesToFilter, error, paymentMethod, affiliationName) => { const { base, orders } = config.URL; ...

Tips for retrieving a local variable from inside a callback and using it outside the function

Recently, I started utilizing npm plaid and I'm looking for a way to access the variable trans outside of the plaidClient.getTransactions function. Any suggestions would be greatly appreciated. var trans; var startDate = moment().subtract(30, &apo ...

Ways to incorporate text using css within a textarea?

I want to include an image on my webpage using the following CSS: { background-image: url(../images/icon_new_reset.png); background-repeat: no-repeat; } Is there a way to provide alternative text or overlay text on this background image? ...

Creating an HTML return statement to specifically target and extract a certain string while disregarding additional data

Looking for a solution to trim a long string returned by a webpage, while ensuring essential data is not removed. Counting characters is not feasible due to the varying length of the return. The return format is as follows: GET /New%20Messenger&subti ...

Vue.js does not support using nested v-for loops with p tags

I'm facing an issue with nesting 2 v-for loops in Vue.js. It seems simple, but for some reason, it's not working as expected and I can't figure out why. Looping through the users and displaying their names works perfectly. Even extracting t ...

How can one guide a glTF model in the direction it is pointed using A-frame?

I have a 3D model of my customized robot loaded in an A-frame scene using version 1.0.4. Currently, I am able to rotate the robot along its x, y, z axes, but I am facing an issue where it continues to move in its original direction rather than the one it i ...

Is it possible to modify this code to accept multiple IDs at once?

I'm attempting to create a form in JavaScript where, upon entering the necessary details and clicking submit, the user's email client opens with the information pre-filled for easy sending. However, I am facing challenges as my code involves mult ...

I am unable to give back an item

I am working with an object structure that looks like this: const obj = { name: 'john', children: [ { name: 'Foo' }, { name: 'Bar', children: [ { name: 'Doe' ...