HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
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.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
If the stylesheet you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
Search for and use JavaScript packages from npm here. By selecting a package, an import
statement will be added to the top of the JavaScript editor for this package.
Using packages here is powered by Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<div class="wrapper">
<main>
<div class="container">
<div class="row">
<div class="col-md-3">
<!-- Sidebar Content -->
<p>First Sidebar Ad</p>
<p>
<a class="open-riser" href="#" data-title="First Marketo Form" data-mktoformid="1534">
<img src="http://placehold.it/260x150">
</a>
</p>
<p>Second Sidebar Ad</p>
<p>
<a class="open-riser" href="#" data-title="Second Marketo Form" data-mktoformid="1551">
<img src="http://placehold.it/260x150">
</a>
</p>
</div>
<!--/.col-md-3-->
<div class="col-md-9">
<!-- Main Content Area -->
<h1>Marketo Double Click Demo</h1>
<h4 style="color:red;">Quicly click the sidebar ads on the left multiple times to see the bug.</h4>
<p>Each sidebar ad has a data-attribute <code>data-mktoformid="XXXX"</code> that contains the form id for the marketo form we want to load into the riser.</p>
<hr />
<p>Lorem ipsum dolor sit amet, sed mollis nullam, dolor aenean adipiscing dolor sapien dapibus. Tortor justo duis. Congue vitae diam. Imperdiet suspendisse justo class nonummy sit. Lacus odio fermentum ac eget, velit sociosqu semper maecenas sodales
natoque, sem integer lobortis, vehicula pellentesque mi, et vestibulum nullam.</p>
<p>Lorem ipsum dolor sit amet, sed mollis nullam, dolor aenean adipiscing dolor sapien dapibus. Tortor justo duis. Congue vitae diam. Imperdiet suspendisse justo class nonummy sit. Lacus odio fermentum ac eget, velit sociosqu semper maecenas sodales
natoque, sem integer lobortis, vehicula pellentesque mi, et vestibulum nullam.</p>
</div>
<!--/.col-md-9 -->
</div>
<!--/.row-->
</div>
<!--/.container-->
</main>
<!-- The overlay that blocks out the page behind the riser from being clicked -->
<div id="PageOverlay" class=""></div>
<!-- Form Riser -->
<div id="FormRiser">
<button id="closeRiser" class="close"><span aria-hidden="true">×</span></button>
<div class="container">
<h1 class="riser-title"></h1>
<div class="form-container">
<!-- this is where the <form> element gets rendered -->
</div>
</div>
</div>
<!--/Form Riser -->
</div>
<!--/.wrapper-->
html,
body{
width: 100%;
height: 100%;
}
.wrapper{
position: relative;
width: 100%;
height: 100%;
}
#PageOverlay {
position: fixed;
display: none;
top: 0;
left: 0;
width: 100%;
height: 100%;
opacity: 0;
background: rgba(42,45,51,.7);
visibility: hidden;
z-index: 9998;
-webkit-transition: all .3s ease;
-moz-transition: all .3s ease;
-o-transition: all .3s ease;
transition: all .3s ease;
}
#FormRiser{
background:orange;
position:fixed;
min-height:300px;
height:auto;
padding:60px 0;
bottom:0;
left:0;
width:100%;
z-index: 9999;
-webkit-transform: translateY(100%);
transform: translateY(100%);
-webkit-transition: all 0.3s ease;
transition: all 0.3s ease;
}
#FormRiser .close{
position:absolute;
top: 20px;
right: 20px;
font-size:36px;
}
/*add .riser-open class to body to trigger riser css*/
body.riser-open #PageOverlay{
display: block;
visibility: visible;
opacity: 1;
}
body.riser-open #PageOverlay:hover{
cursor: pointer;
}
body.riser-open #FormRiser{
-webkit-transform: translateY(0);
transform: translateY(0);
}
var MarketoRiser = (function ($, window, undefined) {
'use strict';
/* Marketo Account */
var MktoAccount = {
baseUrl: '//app-ab17.marketo.com',
munchkinId: '361-IGT-147'
};
/* Riser Variables*/
var body = $('body'),
formContainer = $('.form-container'),
riserTitle = $('.riser-title'),
_isOpen = false;
/**
* Private Methods
*/
function getMktoForm(formid, title){
//set the title in the riser
riserTitle.text(title);
//delete any previous forms inside riser
deleteFormEl();
//create form element dynamically, since we cannot have a <form> tag inside a web form
var formEl = document.createElement("form"); //create form element
formEl.setAttribute("id", "mktoForm_" + formid); //set the form id so Marketo knows where to render the form
formContainer.append(formEl); //add form element inside riser container
console.log('form element created');
//now that the <form> has been created, we need to load the MarketoForm
MktoForms2.loadForm(MktoAccount.baseUrl, MktoAccount.munchkinId, formid);
//when the form has been loaded and ready...
MktoForms2.whenReady(function(form) {
console.log('MktoForms2 is ready');
form.onSuccess(function (values, followUpUrl) {
riserTitle.text('Thank You!'); //set riser title to "thank you"
// form.getFormElem().hide(); // Get the form's jQuery element and hide it
deleteMktoForm(); //delete form element
return false; // Prevent the submission handler from taking the lead to the follow up url
});
});
}
function deleteFormEl(){
if ($('.form-container form').length > 0){
$('.form-container form').remove();
console.log('form element deleted');
}
}
/**
* Public Methods
*/
function OpenRiser(data) {
/* if the riser is closed */
if (!_isOpen) {
_isOpen = true; //set flag to true
console.log("OpenRiser(), _isOpen:true");
body.addClass('riser-open');
//pass the form id and title from the clicked element to the renderForm method
getMktoForm(data.mktoformid, data.title);
}
};
function CloseRiser() {
/* if the riser is open */
if (_isOpen) {
body.removeClass('riser-open');
deleteFormEl();
_isOpen = false; //set flag to true
console.log("CloseRiser(), _isOpen:false");
}
};
//return public methods
return {
OpenRiser: OpenRiser,
CloseRiser: CloseRiser
};
})(jQuery, window);
/*normally the code below is placed on page or
from within another js file, but putting it in
here for readability*/
$(document).ready(function(){
//when a sidebar ad with open-riser class is clicked
$('.open-riser').on('click', function(evt){
evt.preventDefault();
var elData = $(this).data(); //get the data from the data-attributes
MarketoRiser.OpenRiser(elData); //pass the data to the OpenRiser method
});
//when a riser is open we can close it by clicking the close X in the riser,
//or by clicking on the page overlay
$('#closeRiser, #PageOverlay').on('click',function(){
MarketoRiser.CloseRiser();
})
});
Also see: Tab Triggers