LOADING...

Preview

Pen ID
Unlock Campus Themeforest adv

 

Code

Login

Register! Forgot?
CSS
* { box-sizing: border-box }
html, body {
  display: table;
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: #eee;
}
body {
  display: table-cell;
  vertical-align: middle;
}
.box {
  margin: auto;
  padding: 25px 50px;
  width: 350px;
  min-height: 115px;
  background: #fff;
  border-left: 5px solid #9b2;
  box-shadow: 0 0 20px rgba(0,0,0,.15);
  font: 12px/15px Arial, Helvetica, sans-serif;
  color: #666;
}
h2 {
  margin: 0 10px;
  line-height: 40px;
}
form {
  padding: 0 10px 10px;
}
form::after {
  content: "";
  display: block;
  clear: both;
}
label {
  position: absolute;
  left: -9999px;
}
input {
  position: relative;
  z-index: 10;
  margin: 0;
  padding: 0 5px;
  width: 225px;
  height: 30px;
  border: 1px solid #ccc;
}
input:focus {
  z-index: 15;
  box-shadow: 0 0 10px rgba(0,0,0,.1);
  outline: 0;
}
#password {
  top:-1px;
  margin-bottom: 5px;
}
.register-form {
  display: none;
}
.register-form input {
  margin: -1px 0;
}
#first-name {
  margin-top: 5px;
}
.captcha {
  margin: 10px 0;
}
.captcha label {
  position: relative;
  left: 0;
}
#submit {
  float: right;
  padding: 0;
  width: 75px;
  background: #9b2;
  color: #140;
  border-color: #471;
}
#submit:hover {
  color: #025;
  background: #28e;
  border-color: #16c;
}
#submit ~ a {
  display: block;
  float: left;
  width: 120px;
  text-decoration: none;
  color: #666;
}
#submit ~ a:hover {
  text-decoration: underline;
}
JS
(function( $ ){
	   
  // Easing equation based on
  // EaseInOutExpo by Robert Penner (c) 2001
  // robertpenner.com/easing_terms_of_use.html
  
  $.fn.extend( jQuery.easing, {
    eioe: function( ø, t, b, c, d ) {
      if(t==0) return b;
      if(t==d) return b+c;
      if( (t /= d/2) < 1 ) return c/2 * Math.pow( 2, 10 * (t - 1) ) + b;
      return c/2 * ( -Math.pow( 2, -10 * --t ) + 2 ) + b;
    }
  });
  
  // Toggle disabled
  // http://stackoverflow.com/questions/4702000/jquery-toggle-input-disabled-attribute#comment5189637_4702086
  
  $.fn.toggleDisabled = function() {
    return this.each(function() {
      this.disabled = !this.disabled;
    });
  };
  
  // Toggle attribute value
  // Anders Grimsrud, 2013
  
  $.fn.toggleAttr = function(a, v1, v2) {
    return this.each(function() {
      var $t = $(this),
          v  = $t.attr(a) === v1 ? v2 : v1;
      $t.attr(a, v)
        });
  };
  
  // Toggle login/register form
  
  $('.register').click(function(){
    
    // Toggle register form and enable inputs
    $('.register-form').slideToggle({
      easing: 'eioe',
      duration: 250
    }).find('input').toggleDisabled();
    
    // Change header
    // Login -> Register
    var $h2 = $('.box h2'),
        headerText = $h2.text() === "Login" 
        ? "Register" 
        : "Login";
    $h2.text(headerText);
    
    // Change submit button value
    // Login -> Register
    $('#submit').toggleAttr('value','Login','Register');
    
    // Change signup link
    // Signup -> Login link
    var $su = $('.register');
    $su.toggleAttr('href','register.htm','login.htm')
      var signupLinkText = $su.text() === "Register!" 
          ? "Login!" 
          : "Register!";
    $su.text(signupLinkText);
    
    // Hide Forgot password link
    $('.forgot-password').toggle();
    
    // Change form action
    // login.php -> register.php
    $('form').toggleAttr('action','login.php','register.php')
      
      return false;
  });
  
})(jQuery);
Host Instantly Drag and Drop Website Builder

 

Description

A small experiment on utilizing the same form for login and registration.
Term
Wed, 11/29/2017 - 11:21

Related Codes

Pen ID
Pen ID
Pen ID