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 URLs added here will be added as <link>
s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.
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.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and 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 esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM 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="main">
<header>
<p>
An Animated Scroll To Top Button With jQuery
</p>
<p>
by
</p>
<p>
<i>Mostafa Mohamed</i>
</p>
</header>
<div class="left">
<ul>
<li>
<a class="link1" href="">Link 1</a>
</li>
<li>
<a class="link2" href="">Link 2</a>
</li>
<li>
<a class="link3" href="">Link 3</a>
</li>
</ul>
</div>
<div class="right">
<h2 id="h1">
HEADING 1
</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce pellentesque velit nec blandit pharetra. Donec ornare, massa non congue fermentum, tellus turpis congue nisi, non pharetra nisi orci vel nisi. Nam sed vestibulum augue. Morbi vestibulum, ante
sed interdum ultricies, risus nibh consequat tortor, non cursus ante justo in turpis. Sed nec diam ultrices, venenatis tortor at, eleifend tellus. Donec id ornare tortor. Cras rutrum vel tortor suscipit fermentum. Sed molestie neque ultrices, consequat
risus id, suscipit enim. Duis arcu nibh, interdum nec est ut, gravida molestie urna. Integer quam ante, aliquet a pretium vitae, tempor vitae diam. Maecenas eros risus, fermentum vitae congue interdum, pulvinar non leo. Suspendisse sit amet dignissim
massa, ac ullamcorper urna. In hac habitasse platea dictumst. Cras tincidunt orci lorem, eget placerat dui consectetur vel. Donec convallis in dolor quis laoreet. Nunc quis fringilla tellus. Interdum et malesuada fames ac ante ipsum primis in faucibus.
Nullam congue felis ut lectus porttitor faucibus. Curabitur vitae lorem vestibulum, blandit dui at, luctus justo. Morbi lectus eros, faucibus luctus feugiat commodo, lobortis sed nulla. Fusce et fermentum ante. Vivamus consequat varius sem, eget
hendrerit lectus tempus ac. In hac habitasse platea dictumst. Cras imperdiet elit id auctor tincidunt. Morbi eu leo eros. Etiam ultricies ornare adipiscing. Mauris interdum eleifend congue. Curabitur eu ante sed turpis fermentum iaculis sed vitae
nibh. Duis sapien tellus, laoreet at dignissim non, congue id nisi. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce pellentesque velit nec blandit pharetra. Donec ornare, massa non congue fermentum, tellus turpis congue nisi, non
pharetra nisi orci vel nisi. Nam sed vestibulum augue. Morbi vestibulum, ante sed interdum ultricies, risus nibh consequat tortor, non cursus ante justo in turpis. Sed nec diam ultrices, venenatis tortor at, eleifend tellus. Donec id ornare tortor.
Cras rutrum vel tortor suscipit fermentum. Sed molestie neque ultrices, consequat risus id, suscipit enim. Duis arcu nibh, interdum nec est ut, gravida molestie urna. Integer quam ante, aliquet a pretium vitae, tempor vitae diam. Maecenas eros risus,
fermentum vitae congue interdum, pulvinar non leo. Suspendisse sit amet dignissim massa, ac ullamcorper urna. In hac habitasse platea dictumst. Cras tincidunt orci lorem, eget placerat dui consectetur vel. Donec convallis in dolor quis laoreet.
Nunc quis fringilla tellus. Interdum et malesuada fames ac ante ipsum primis in faucibus. Nullam congue felis ut lectus porttitor faucibus. Curabitur vitae lorem vestibulum, blandit dui at, luctus justo. Morbi lectus eros, faucibus luctus feugiat
commodo, lobortis sed nulla. Fusce et fermentum ante. Vivamus consequat varius sem, eget hendrerit lectus tempus ac. In hac habitasse platea dictumst. Cras imperdiet elit id auctor tincidunt. Morbi eu leo eros. Etiam ultricies ornare adipiscing.
Mauris interdum eleifend congue. Curabitur eu ante sed turpis fermentum iaculis sed vitae nibh. Duis sapien tellus, laoreet at dignissim non, congue id nisi.
</p>
<h2 id="h2">
HEADING 2
</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce pellentesque velit nec blandit pharetra. Donec ornare, massa non congue fermentum, tellus turpis congue nisi, non pharetra nisi orci vel nisi. Nam sed vestibulum augue. Morbi vestibulum, ante
sed interdum ultricies, risus nibh consequat tortor, non cursus ante justo in turpis. Sed nec diam ultrices, venenatis tortor at, eleifend tellus. Donec id ornare tortor. Cras rutrum vel tortor suscipit fermentum. Sed molestie neque ultrices, consequat
risus id, suscipit enim. Duis arcu nibh, interdum nec est ut, gravida molestie urna. Integer quam ante, aliquet a pretium vitae, tempor vitae diam. Maecenas eros risus, fermentum vitae congue interdum, pulvinar non leo. Suspendisse sit amet dignissim
massa, ac ullamcorper urna. In hac habitasse platea dictumst. Cras tincidunt orci lorem, eget placerat dui consectetur vel. Donec convallis in dolor quis laoreet. Nunc quis fringilla tellus. Interdum et malesuada fames ac ante ipsum primis in faucibus.
Nullam congue felis ut lectus porttitor faucibus. Curabitur vitae lorem vestibulum, blandit dui at, luctus justo. Morbi lectus eros, faucibus luctus feugiat commodo, lobortis sed nulla. Fusce et fermentum ante. Vivamus consequat varius sem, eget
hendrerit lectus tempus ac. In hac habitasse platea dictumst. Cras imperdiet elit id auctor tincidunt. Morbi eu leo eros. Etiam ultricies ornare adipiscing. Mauris interdum eleifend congue. Curabitur eu ante sed turpis fermentum iaculis sed vitae
nibh. Duis sapien tellus, laoreet at dignissim non, congue id nisi. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce pellentesque velit nec blandit pharetra. Donec ornare, massa non congue fermentum, tellus turpis congue nisi, non
pharetra nisi orci vel nisi. Nam sed vestibulum augue. Morbi vestibulum, ante sed interdum ultricies, risus nibh consequat tortor, non cursus ante justo in turpis. Sed nec diam ultrices, venenatis tortor at, eleifend tellus. Donec id ornare tortor.
Cras rutrum vel tortor suscipit fermentum. Sed molestie neque ultrices, consequat risus id, suscipit enim. Duis arcu nibh, interdum nec est ut, gravida molestie urna. Integer quam ante, aliquet a pretium vitae, tempor vitae diam. Maecenas eros risus,
fermentum vitae congue interdum, pulvinar non leo. Suspendisse sit amet dignissim massa, ac ullamcorper urna. In hac habitasse platea dictumst. Cras tincidunt orci lorem, eget placerat dui consectetur vel. Donec convallis in dolor quis laoreet.
Nunc quis fringilla tellus. Interdum et malesuada fames ac ante ipsum primis in faucibus. Nullam congue felis ut lectus porttitor faucibus. Curabitur vitae lorem vestibulum, blandit dui at, luctus justo. Morbi lectus eros, faucibus luctus feugiat
commodo, lobortis sed nulla. Fusce et fermentum ante. Vivamus consequat varius sem, eget hendrerit lectus tempus ac. In hac habitasse platea dictumst. Cras imperdiet elit id auctor tincidunt. Morbi eu leo eros. Etiam ultricies ornare adipiscing.
Mauris interdum eleifend congue. Curabitur eu ante sed turpis fermentum iaculis sed vitae nibh. Duis sapien tellus, laoreet at dignissim non, congue id nisi.
</p>
<h2 id="h3">
HEADING 3
</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce pellentesque velit nec blandit pharetra. Donec ornare, massa non congue fermentum, tellus turpis congue nisi, non pharetra nisi orci vel nisi. Nam sed vestibulum augue. Morbi vestibulum, ante
sed interdum ultricies, risus nibh consequat tortor, non cursus ante justo in turpis. Sed nec diam ultrices, venenatis tortor at, eleifend tellus. Donec id ornare tortor. Cras rutrum vel tortor suscipit fermentum. Sed molestie neque ultrices, consequat
risus id, suscipit enim. Duis arcu nibh, interdum nec est ut, gravida molestie urna. Integer quam ante, aliquet a pretium vitae, tempor vitae diam. Maecenas eros risus, fermentum vitae congue interdum, pulvinar non leo. Suspendisse sit amet dignissim
massa, ac ullamcorper urna. In hac habitasse platea dictumst. Cras tincidunt orci lorem, eget placerat dui consectetur vel. Donec convallis in dolor quis laoreet. Nunc quis fringilla tellus. Interdum et malesuada fames ac ante ipsum primis in faucibus.
Nullam congue felis ut lectus porttitor faucibus. Curabitur vitae lorem vestibulum, blandit dui at, luctus justo. Morbi lectus eros, faucibus luctus feugiat commodo, lobortis sed nulla. Fusce et fermentum ante. Vivamus consequat varius sem, eget
hendrerit lectus tempus ac. In hac habitasse platea dictumst. Cras imperdiet elit id auctor tincidunt. Morbi eu leo eros. Etiam ultricies ornare adipiscing. Mauris interdum eleifend congue. Curabitur eu ante sed turpis fermentum iaculis sed vitae
nibh. Duis sapien tellus, laoreet at dignissim non, congue id nisi. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce pellentesque velit nec blandit pharetra. Donec ornare, massa non congue fermentum, tellus turpis congue nisi, non
pharetra nisi orci vel nisi. Nam sed vestibulum augue. Morbi vestibulum, ante sed interdum ultricies, risus nibh consequat tortor, non cursus ante justo in turpis. Sed nec diam ultrices, venenatis tortor at, eleifend tellus. Donec id ornare tortor.
Cras rutrum vel tortor suscipit fermentum. Sed molestie neque ultrices, consequat risus id, suscipit enim. Duis arcu nibh, interdum nec est ut, gravida molestie urna. Integer quam ante, aliquet a pretium vitae, tempor vitae diam. Maecenas eros risus,
fermentum vitae congue interdum, pulvinar non leo. Suspendisse sit amet dignissim massa, ac ullamcorper urna. In hac habitasse platea dictumst. Cras tincidunt orci lorem, eget placerat dui consectetur vel. Donec convallis in dolor quis laoreet.
Nunc quis fringilla tellus. Interdum et malesuada fames ac ante ipsum primis in faucibus. Nullam congue felis ut lectus porttitor faucibus. Curabitur vitae lorem vestibulum, blandit dui at, luctus justo. Morbi lectus eros, faucibus luctus feugiat
commodo, lobortis sed nulla. Fusce et fermentum ante. Vivamus consequat varius sem, eget hendrerit lectus tempus ac. In hac habitasse platea dictumst. Cras imperdiet elit id auctor tincidunt. Morbi eu leo eros. Etiam ultricies ornare adipiscing.
Mauris interdum eleifend congue. Curabitur eu ante sed turpis fermentum iaculis sed vitae nibh. Duis sapien tellus, laoreet at dignissim non, congue id nisi.
</p>
</div>
<footer></footer>
<div id="stop" class="scrollTop">
<span><a href="">Top</a></span>
</div>
</div>
<!-- main-->
*:before,
*:after {
box-sizing: border-box;
}
body {
background-color: #3e3e3e;
color: #444;
font-family: arial;
}
header {
text-align: center;
font-size: 25px;
text-transform: uppercase;
background-color: #F2F2F2;
padding: 20px;
}
header p {
margin: 0px;
}
header p:last-child {
color: #BE3F48;
}
.main {
width: 760px;
margin: 0 auto;
background-color: #fff;
position: relative!important;
padding: 20px;
}
.left,
.right {
float: left;
display: block;
}
.left {
width: 200px;
padding: 10px;
}
.left ul {
position: fixed;
display: block;
background-color: #F2F2F2;
padding: 0px;
}
.left ul li {
list-style: none;
line-height: 30px;
}
.left ul li a {
color: #000000;
display: block;
padding: 5px;
text-align: center;
text-decoration: none;
width: 190px;
}
.left ul li a:hover {
background-color: #E4E4E4;
}
.right {
width: 520px;
padding: 10px;
}
.right > p {
margin-bottom: 40px;
}
#h1 {
background-color: #497493;
color: #fff;
padding: 5px 10px;
}
#h2 {
background-color: #B84A4A;
color: #fff;
padding: 5px 10px;
}
#h3 {
background-color: #538253;
color: #fff;
padding: 5px 10px;
}
footer {
clear: both;
}
/****************************************
IMPORTANT
*****************************************/
.scrollTop {
position: fixed;
right: 10%;
bottom: 10px;
background-color: #BE3F48;
padding: 20px;
opacity: 0;
transition: all 0.4s ease-in-out 0s;
}
.scrollTop a {
font-size: 18px;
color: #fff;
}
// BY KAREN GRIGORYAN
$(document).ready(function() {
/******************************
BOTTOM SCROLL TOP BUTTON
******************************/
// declare variable
var scrollTop = $(".scrollTop");
$(window).scroll(function() {
// declare variable
var topPos = $(this).scrollTop();
// if user scrolls down - show scroll to top button
if (topPos > 100) {
$(scrollTop).css("opacity", "1");
} else {
$(scrollTop).css("opacity", "0");
}
}); // scroll END
//Click event to scroll to top
$(scrollTop).click(function() {
$('html, body').animate({
scrollTop: 0
}, 800);
return false;
}); // click() scroll top EMD
/*************************************
LEFT MENU SMOOTH SCROLL ANIMATION
*************************************/
// declare variable
var h1 = $("#h1").position();
var h2 = $("#h2").position();
var h3 = $("#h3").position();
$('.link1').click(function() {
$('html, body').animate({
scrollTop: h1.top
}, 500);
return false;
}); // left menu link2 click() scroll END
$('.link2').click(function() {
$('html, body').animate({
scrollTop: h2.top
}, 500);
return false;
}); // left menu link2 click() scroll END
$('.link3').click(function() {
$('html, body').animate({
scrollTop: h3.top
}, 500);
return false;
}); // left menu link3 click() scroll END
}); // ready() END
Also see: Tab Triggers