css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <html>

<head>

  <meta charset="UTF-8">

  <title>Custom Events Support - Thanks to Tushar Sonawane </title>

    <!-- 2- Incluir AniCollection.css library -->
    <link rel="stylesheet" href="https://anijs.github.io/lib/anicollection/anicollection.css">
    
</head>

<body>

  <body>
	<div class="question">
		<div class="question-screen" data-anijs="if: answerSuccess, on: $Security, do: rubberBand animated, after: removeAnim">
			<div class="app-title">
				<h2 id="loadajax">Answer Please :)</h2>
			</div>

			<div class="question-form">
				<div class="control-group">
				<input type="text" class="question-field" id="questionfield" value="8 + 6 * 3 ?" placeholder="How much is 8 + 6 * 3 ?" id="question-name">
				<label class="question-field-icon fui-user" for="question-name"></label>
				</div>

				<div class="control-group">
				<input data-anijs="if: answerError, on: $Security, do: bad, after: removeAnim" id="answerfield" class="question-field" value="" placeholder="Answer here" id="question-pass">
				<label class="question-field-icon fui-lock" for="question-pass"></label>
				</div>

				<a id="questionButton" data-anijs="if: animationend, on: input, do: rollOut animated, to: div.question-screen, after: removeAnim; if: click, do: pulse animated, to: .question-screen, after: removeAnim" class="btn btn-primary btn-large btn-block" href="#">Answer me!</a>
				<a class="question-link" href="https://anijs.github.io/">Discover AniJS</a>
			</div>
		</div>
	</div>
</body>
</html>
            
          
!
            
              /* Note: Prefixes omitted, see below */
.bad {
	-webkit-animation-name: color_change;
	animation-name: color_change;
	-webkit-animation-duration: 1s;
	animation-duration: 1s;
	-webkit-animation-iteration-count: 1;
	animation-iteration-count: 1;
}

@-webkit-keyframes color_change {
	from { border-color: white; color: #FF6530;}
	to { border-color: #FF6530; color: #FF6530;}
}

@-moz-keyframes color_change {
	from { border-color: white; color: #FF6530;}
	to { border-color: #FF6530; color: #FF6530;}
}
@-o-keyframes color_change {
	from { border-color: white; color: #FF6530;}
	to { border-color: #FF6530; color: #FF6530;}
}
@keyframes color_change {
	from { border-color: white; color: #FF6530;}
	to { border-color: #FF6530; color: #FF6530;}
}


* {
-moz-box-sizing: border-box;
box-sizing: border-box;
}

*:focus {
	outline: none;
}
body {
	font-family: Arial;
	background-color: #3498DB;
	padding: 50px;
}
.question {
	margin: 20px auto;
	width: 300px;
}
.question-screen {
	background-color: #FFF;
	padding: 20px;
	border-radius: 5px
}

.app-title {
	text-align: center;
	color: #777;
}

.question-form {
	text-align: center;
}
.control-group {
	margin-bottom: 10px;
}

input {
	text-align: center;
	background-color: #ECF0F1;
	border: 2px solid transparent;
	border-radius: 3px;
	font-size: 16px;
	font-weight: 200;
	padding: 10px 0;
	width: 250px;
	-webkit-transition: border .5s;
	transition: border .5s;
}

input:focus {
	border: 2px solid #3498DB;
	box-shadow: none;
}

.btn {
	border: 2px solid transparent;
	background: #3498DB;
	color: #ffffff;
	font-size: 16px;
	line-height: 25px;
	padding: 10px 0;
	text-decoration: none;
	text-shadow: none;
	border-radius: 3px;
	box-shadow: none;
	-webkit-transition: 0.25s;
	transition: 0.25s;
	display: block;
	width: 250px;
	margin: 0 auto;
}

.btn:hover {
	background-color: #2980B9;
}

.question-link {
	font-size: 12px;
	color: #444;
	display: block;
	margin-top: 12px;
}
            
          
!
            
              		AniJS.run();
		var MyApp = {};

		//Obtaining the Notifier
		MyApp.SecurityNotifier = AniJS.getNotifier('Security');

		MyApp.processError = function(message){

			//Right now the events triggered by SecurityNotifier can be listened by AniJS
			$(MyApp.SecurityNotifier).trigger('answerError');
			document.getElementById('loadajax').innerHTML = message;
		}

		MyApp.processSuccess = function(message){

			//Right now the events triggered by SecurityNotifier can be listened by AniJS
			$(MyApp.Notifier).trigger('answerSuccess');
			document.getElementById('loadajax').innerHTML = message;
		}


		//Using native API to listen for the user click
		//https://developer.mozilla.org/en-US/docs/Web/API/Event
		formButton = document.getElementById("questionButton");
		questionButton.addEventListener('click', function(e){

			var request = document.getElementById('answerfield').value;

			document.getElementById('loadajax').innerHTML = 'Processing...';
	

			//Now you can wait for an Ajax Response
			MyApp.someAjaxModule.getResponse(request, function(response){

				if(response.error){
					MyApp.processError(response.error);
				} else{
					MyApp.processSuccess(response.success);
				}
				
			})
		

		}, false);

		//It's just a simulation
		MyApp.someAjaxModule = {
			getResponse: function(data, callback){
				var response = {};
				if( data === '26'){
					response.success = 'Cool :)';
				} else {
					response.error = 'Bad :(';
				}
				setTimeout(function(){
					callback(response);
				}, 1300)
			}
		}
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console