Pen Settings

HTML

CSS

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

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

Behavior

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <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>
              
            
!

CSS

              
                /* 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;
}
              
            
!

JS

              
                		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

Console