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. You can use the CSS from another Pen by using it's URL and the proper URL extention.
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 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.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="base.css">
<title>Scroll To Accept</title>
</head>
<body>
<h1>Drew Learns how to make <br> A scroll to accept page</h1>
<div class="wrapper">
<div class="terms-and-conditions">
<p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Iste, labore!</p>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Rerum assumenda, ullam, sed quo ipsam officia
asperiores minima excepturi eveniet reiciendis velit debitis temporibus explicabo. Incidunt sit itaque,
reprehenderit fuga voluptatem officiis corrupti ipsa eveniet architecto dolorem magni facere doloribus aut
veritatis sequi quia repellendus aperiam assumenda exercitationem optio praesentium debitis. Excepturi unde
minus dignissimos at totam tempora beatae cumque, voluptates adipisci repudiandae asperiores repellat delectus
tempore voluptatem veritatis atque quaerat optio! Quasi, possimus molestiae hic modi quia minus eius veniam
aperiam assumenda fugiat fugit optio odio quas esse quam architecto officiis sunt quis cupiditate vel
voluptate
consequuntur nam porro harum. Fuga distinctio voluptate provident molestias perspiciatis fugit esse corrupti
adipisci quas eos dolor non cum ipsam repudiandae dolorem, quasi necessitatibus iusto unde similique
repellendus praesentium tenetur? Obcaecati aliquam nostrum vero expedita fuga, quae et quaerat modi error
adipisci eligendi fugit alias quia nihil laudantium quam tenetur ipsam explicabo nisi natus, rerum omnis,
debitis provident! Dolorum sequi recusandae, necessitatibus eos nesciunt cupiditate accusantium illum unde
minima. Labore sit quos voluptatem illum qui. Veritatis quis a mollitia asperiores repudiandae consequatur
assumenda, at tempora, modi voluptate sit blanditiis hic dignissimos harum consequuntur quia ipsam, architecto
nesciunt. Praesentium, mollitia? Delectus quod laudantium doloremque nihil?</p>
<p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Quos ab, ea inventore commodi eligendi error
repellat impedit eum quod enim sequi, distinctio, qui eaque ipsam fugit asperiores eos laboriosam ex.</p>
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Ipsa id debitis ex eligendi rem unde consequuntur
natus omnis vel nulla sit commodi, quos distinctio doloremque doloribus veniam quis et dolore?</p>
<p>Lorem ipsum dolor sit amet consectetur, adipisicing elit. Commodi laboriosam nulla est architecto eum,
dolorem
quam, unde quo fugit tempore ipsa qui provident, iste ratione quis dignissimos temporibus nostrum voluptatum
molestias? Blanditiis repellendus sapiente inventore aliquam qui error aliquid doloremque fugit consequuntur
laudantium. Sapiente doloribus ullam vel dicta doloremque iure, deleniti ipsum non. Rem repudiandae deleniti
ad
at laborum eaque, modi voluptas aut! Quam nihil deleniti velit excepturi, quidem, veniam aut doloremque iure
reprehenderit natus vel quia iusto? Magni veritatis provident libero hic quisquam, perferendis officia quasi
molestiae sit sunt fugiat, perspiciatis architecto velit unde molestias ratione totam, atque doloremque!</p>
<hr>
</div>
<button class="accept" disabled>Accept</button>
</div>
<script type="text/javascript" src="scroll.js"></script>
</body>
</html>
body {
min-height: 100vh;
display: grid;
justify-content: center;
align-content: center;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
line-height: 2;
background-color: #0072B9;
background-image: url("data:image/svg+xml,%3Csvg width='20' height='100' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0 21.184c.13.357.264.72.402 1.088l.661 1.768C4.653 33.64 6 39.647 6 50c0 10.271-1.222 15.362-4.928 24.629-.383.955-.74 1.869-1.072 2.75v6.225c.73-2.51 1.691-5.139 2.928-8.233C6.722 65.888 8 60.562 8 50c0-10.626-1.397-16.855-5.063-26.66l-.662-1.767C1.352 19.098.601 16.913 0 14.85v6.335zm20 0C17.108 13.258 16 8.077 16 0h2c0 5.744.574 9.951 2 14.85v6.334zm0 56.195c-2.966 7.86-4 13.123-4 22.621h2c0-6.842.542-11.386 2-16.396v-6.225zM6 0c0 8.44 1.21 13.718 4.402 22.272l.661 1.768C14.653 33.64 16 39.647 16 50c0 10.271-1.222 15.362-4.928 24.629C7.278 84.112 6 89.438 6 100h2c0-10.271 1.222-15.362 4.928-24.629C16.722 65.888 18 60.562 18 50c0-10.626-1.397-16.855-5.063-26.66l-.662-1.767C9.16 13.223 8 8.163 8 0H6z' fill='%23fff' fill-rule='nonzero' fill-opacity='.1' opacity='.349'/%3E%3C/svg%3E%0A");
}
.wrapper {
width: 400px;
max-height: 60vh;
padding: 20px;
border: 1px solid black;
background: white;
display: grid;
grid-template-rows: 1fr auto;
border-radius: 5px;
}
button {
background: #61e846;
color: white;
font-size: 1rem;
padding: 20px;
transition: all 0.2s;
border-radius: 5px;
}
button[disabled] {
background-color: grey;
opacity: 0.4;
/* transform: translateX(-250%) scale(0.5); */
}
.terms-and-conditions {
overflow: scroll;
}
h1 {
text-align: center;
text-transform: capitalize;
}
const terms = document.querySelector('.terms-and-conditions');
const button = document.querySelector('.accept');
function obCallback(payload){
if (payload[0].intersectionRatio > .9) {
button.disabled = false;
ob.unobserve(terms) //clean up
}else { button.disabled = true;
}
}
const ob = new IntersectionObserver(obCallback, {
root: terms, // this is the object it's observing
threshold: [.9]} // 90% on the page
); //doesn't do anything yet, it's just a watcher you haven't called
ob.observe(terms.lastElementChild); //observing for the HR tag
//*****************************************
//OLD WAY TO DO THIS:
// terms.addEventListener('scroll', function(event){
// // console.log(event.currentTarget);
// console.log(event.currentTarget.scrollTop);
// console.log(event.currentTarget.scrollHeight);
// })
//*****************************************
//IF YOU ARE GOING TO ADD THIS TO AN ENTIRE PROJECT NEST THE ABOVE IN HERE:
// function scrollToAccept (){
// if(!terms){
// console.log('no terms and agreements on this page')
// return; //quit this doesn't exist on the page
// }
// }
Also see: Tab Triggers