» » Switching Login and registration form in pop-up window by jQuery

 

Switching Login and registration form in pop-up window by jQuery

Author: bamboo06 on 10-08-2015, 00:38, views: 16483

11
When you click on a page log-in or register button it will pop up a modal window which is a pop-up layer, we can easily switch on the popup login and registration form, a great convenience to users, without shutting down the floor to go click on to other operations, on many sites it has been widely used.

We will use examples to achieve this effect by using jQuery, CSS3 and HTML5 technologies.

HTML
We are now setting up two links on the main page button, login and registration button.
		<nav class="main_nav">
			<ul>
				<li><a class="cd-signin" href="#0">Login</a></li>
				<li><a class="cd-signup" href="#0">Register</a></li>
			</ul>
		</nav>

Then, set up the modal window pops layer div.cd-user-modal, place two for the handover link ul.cd-switcher in the pop-up layer, then place a login and registration form, corresponding div # cd-login and div # cd-signup.
	<div class="cd-user-modal"> 
		<div class="cd-user-modal-container">
			<ul class="cd-switcher">
				<li><a href="#0">Login</a></li>
				<li><a href="#0">Register</a></li>
			</ul>

			<div id="cd-login"> <!-- login -->
				<form class="cd-form">
					<p class="fieldset">
						<label class="image-replace cd-username" for="signin-username">Username</label>
						<input class="full-width has-padding has-border" id="signin-username" type="text" placeholder="input username">
					</p>

					<p class="fieldset">
						<label class="image-replace cd-password" for="signin-password">Password</label>
						<input class="full-width has-padding has-border" id="signin-password" type="text"  placeholder="input password">
					</p>

					<p class="fieldset">
						<input type="checkbox" id="remember-me" checked>
						<label for="remember-me">Remember</label>
					</p>

					<p class="fieldset">
						<input class="full-width2" type="submit" value="Login">
					</p>
				</form>
			</div>

			<div id="cd-signup"> <!-- register form -->
				<form class="cd-form">
					<p class="fieldset">
						<label class="image-replace cd-username" for="signup-username">Username</label>
						<input class="full-width has-padding has-border" id="signup-username" type="text" placeholder="input username">
					</p>

					<p class="fieldset">
						<label class="image-replace cd-email" for="signup-email">Email</label>
						<input class="full-width has-padding has-border" id="signup-email" type="email" placeholder="input email">
					</p>

					<p class="fieldset">
						<label class="image-replace cd-password" for="signup-password">Password</label>
						<input class="full-width has-padding has-border" id="signup-password" type="text"  placeholder="input password">
					</p>

					<p class="fieldset">
						<input type="checkbox" id="accept-terms">
						<label for="accept-terms">I have read <a href="#0">User Agreement</a></label>
					</p>

					<p class="fieldset">
						<input class="full-width2" type="submit" value="Register">
					</p>
				</form>
			</div>

			<a href="#0" class="cd-close-form">Close</a>
		</div>
	</div>

These are the entire html structure.

CSS

The default modal window has the visibility: hidden; and opacity: 0; style, which is not visible by default. By .is-visible to determine whether pop-up display. Here are the main css code css code in more detail, please download the source code view.
.cd-user-modal { 
  position: fixed; 
  top: 0; 
  left: 0; 
  width: 100%; 
  height: 100%; 
  background: rgba(52, 54, 66, 0.9); 
  z-index: 3; 
  overflow-y: auto; 
  cursor: pointer; 
  visibility: hidden; 
  opacity: 0; 
  -webkit-transition: opacity 0.3s 0, visibility 0 0.3s; 
  -moz-transition: opacity 0.3s 0, visibility 0 0.3s; 
  transition: opacity 0.3s 0, visibility 0 0.3s; 
} 
.cd-user-modal.is-visible { 
  visibility: visible; 
  opacity: 1; 
  -webkit-transition: opacity 0.3s 0, visibility 0 0; 
  -moz-transition: opacity 0.3s 0, visibility 0 0; 
  transition: opacity 0.3s 0, visibility 0 0; 
} 
.cd-user-modal.is-visible .cd-user-modal-container { 
  -webkit-transform: translateY(0); 
  -moz-transform: translateY(0); 
  -ms-transform: translateY(0); 
  -o-transform: translateY(0); 
  transform: translateY(0); 
} 
 
.cd-user-modal-container { 
  position: relative; 
  width: 90%; 
  max-width: 600px; 
  background: #FFF; 
  margin: 3em auto 4em; 
  cursor: auto; 
  border-radius: 0.25em; 
  -webkit-transform: translateY(-30px); 
  -moz-transform: translateY(-30px); 
  -ms-transform: translateY(-30px); 
  -o-transform: translateY(-30px); 
  transform: translateY(-30px); 
  -webkit-transition-property: -webkit-transform; 
  -moz-transition-property: -moz-transform; 
  transition-property: transform; 
  -webkit-transition-duration: 0.3s; 
  -moz-transition-duration: 0.3s; 
  transition-duration: 0.3s; 
} 
.cd-user-modal-container .cd-switcher:after { 
  content: ""; 
  display: table; 
  clear: both; 
} 
.cd-user-modal-container .cd-switcher li { 
  width: 50%; 
  float: left; 
  text-align: center; 
} 
.cd-user-modal-container .cd-switcher li:first-child a { 
  border-radius: .25em 0 0 0; 
} 
.cd-user-modal-container .cd-switcher li:last-child a { 
  border-radius: 0 .25em 0 0; 
} 
.cd-user-modal-container .cd-switcher a { 
  display: block; 
  width: 100%; 
  height: 50px; 
  line-height: 50px; 
  background: #d2d8d8; 
  color: #809191; 
} 
.cd-user-modal-container .cd-switcher a.selected { 
  background: #FFF; 
  color: #505260; 
} 
 
#cd-login, #cd-signup { 
  display: none; 
} 
 
#cd-login.is-selected, #cd-signup.is-selected{ 
  display: block; 
} 


jQuery
Pop on and off the effect of the popup invocation style .is-visible by jquery control, switching form is invoked demonstrates .is-selected by jQuery control.
jQuery(document).ready(function($){
	var $form_modal = $('.cd-user-modal'),
		$form_login = $form_modal.find('#cd-login'),
		$form_signup = $form_modal.find('#cd-signup'),
		$form_modal_tab = $('.cd-switcher'),
		$tab_login = $form_modal_tab.children('li').eq(0).children('a'),
		$tab_signup = $form_modal_tab.children('li').eq(1).children('a'),
		$main_nav = $('.main_nav');

	//pop up
	$main_nav.on('click', function(event){

		if( $(event.target).is($main_nav) ) {
			// on mobile open the submenu
			$(this).children('ul').toggleClass('is-visible');
		} else {
			// on mobile close submenu
			$main_nav.children('ul').removeClass('is-visible');
			//show modal layer
			$form_modal.addClass('is-visible');	
			//show the selected form
			( $(event.target).is('.cd-signup') ) ? signup_selected() : login_selected();
		}

	});

	//close popup
	$('.cd-user-modal').on('click', function(event){
		if( $(event.target).is($form_modal) || $(event.target).is('.cd-close-form') ) {
			$form_modal.removeClass('is-visible');
		}	
	});
	//use Esc key to close popup
	$(document).keyup(function(event){
    	if(event.which=='27'){
    		$form_modal.removeClass('is-visible');
	    }
    });

	//switching form
	$form_modal_tab.on('click', function(event) {
		event.preventDefault();
		( $(event.target).is( $tab_login ) ) ? login_selected() : signup_selected();
	});

	function login_selected(){
		$form_login.addClass('is-selected');
		$form_signup.removeClass('is-selected');
		$form_forgot_password.removeClass('is-selected');
		$tab_login.addClass('selected');
		$tab_signup.removeClass('selected');
	}

	function signup_selected(){
		$form_login.removeClass('is-selected');
		$form_signup.addClass('is-selected');
		$form_forgot_password.removeClass('is-selected');
		$tab_login.removeClass('selected');
		$tab_signup.addClass('selected');
	}

});


//credits http://css-tricks.com/snippets/jquery/move-cursor-to-end-of-textarea-or-input/
jQuery.fn.putCursorAtEnd = function() {
	return this.each(function() {
    	// If this function exists...
    	if (this.setSelectionRange) {
      		// ... then use it (Doesn't work in IE)
      		// Double the length because Opera is inconsistent about whether a carriage return is one character or two. Sigh.
      		var len = $(this).val().length * 2;
      		this.setSelectionRange(len, len);
    	} else {
    		// ... otherwise replace the contents with itself
    		// (Doesn't work in Google Chrome)
      		$(this).val($(this).val());
    	}
	});
};


The instance on mobile phones and other mobile devices also have a good display of results, due to the use css3 effect, so if you use IE, upgrade to IE9 version above. It is strongly recommended that you download the source code, a little change can be applied to direct your project.

Category: Javascript / CSS / HTML5

Dear visitor, you are browsing our website as Guest.
We strongly recommend you to register and login to view hidden contents.
<
  • 0 Comments
  • 0 Articles
4 June 2016 17:10

Hasanur Jaman

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
Please tell me this popup will work on bootstrap

<
  • 0 Comments
  • 0 Articles
29 March 2017 22:49

Pharmb646

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
Hello! gddadeb interesting gddadeb site! I'm really like it! Very, very gddadeb good!

Hello! eaagfce interesting eaagfce site! I'm really like it! Very, very eaagfce good!

<
  • 0 Comments
  • 0 Articles
29 September 2017 05:19

nayyak

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
I am going to download this demo once this meeting with the cheap essay writers is over. I just can't believe this meeting has gone on for this long.

<
  • 0 Comments
  • 0 Articles
4 October 2017 10:02

ali

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
You ought to basically fantastic not to mention solid advice, which means notice: Greek Yogurt Benefits

I have a similar interest this is my page read everything carefully and let me know what you think. 100 questions

<
  • 0 Comments
  • 0 Articles
8 October 2017 22:00

mellisa

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
Wow this is so cool, there is even a vr headset system available here as well, i didnt know i could have this facility as well, you guys are doing a pretty good job here i see!! So i wish you all the best!!

<
  • 0 Comments
  • 0 Articles
14 October 2017 05:18

carl

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
We specialize in creating luxurious escapes both at the pre-spec and custom level. Combining functionality, beauty and efficiency we consider every home we build to be a masterpiece. We focus our efforts on the most sought-after locations throughout the G.T.A. mana kitchen design

<
  • 0 Comments
  • 0 Articles
25 October 2017 18:48

frank

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
We specialize in creating luxurious escapes both at the pre-spec and custom level. Combining functionality, beauty and efficiency we consider every home we build to be a masterpiece. We focus our efforts on the most sought-after locations throughout the G.T.A Kitchen Cabinet woodbridge

<
  • 0 Comments
  • 0 Articles
20 January 2018 11:24

Randyesone

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
The Geek Reveals - Top 5 Beginner Binary Options Strategies

24 Binary Alerts

Go to Site: --> http://t.co/bhVIOc6bGg


http://imp-mebeli.ru

<
  • 0 Comments
  • 0 Articles
21 January 2018 13:54

Craigjutty

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
Приобрести можно на веб-сайте http://tedsjkpb.bestseller-super.ru

Предлагаем нашим клиентам инновационное средство для похудения сироп Мангустина. С его помощью реально сбросить около 15 кг за 14 дней.

Дерево гарциния произрастает в Таиланде. Плоды растения имеют замечательные особенности. В баночке имеется более 25 плодов этого замечательного растения. Плоды растения гарциния помогают сжечь лишнюю жировую ткань. Также замечательно воздействуют на человека в целом. Специфика производства средства, а также уникальная упаковка позволяют сберечь все полезные свойства растения.

Главным действующим компонентом сиропа Mangoosteen являются фрукты с растения гарциния, в них содержится большое число питательных микроэлементов. Благодаря веществу ксантону, которое в больших количествах имеется в плодах, сильно замедляются окислительные процессы в организме. Ксантон считается одним из самых сильных антиоксидантов. В плоде дерева мангостан к тому же имеются различные группы витаминов и элементы. Купить сироп Мансустина возможно на сайте http://tedsjkpb.bestseller-super.ru.

<
  • 0 Comments
  • 0 Articles
13 February 2018 16:34

Belkin.setup

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
Thanks for sharing this marvelous post. I m very pleased to read this article. Belkin.setup

<
  • 0 Comments
  • 0 Articles
20 February 2018 21:12

Norton setup

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
I really like to appreciate you for this.If you are experiencing trouble logging into your Norton account,Norton setup,Norton Activation,Norton installation please visit
www.norton.com/setup or directly visit
Norton setup
To be Secure and be Aware of avoiding any software conflict.

Information
Comment on the news site is possible only within (days) days from the date of publication.