Square animation on scroll
How do I make an square animation on scroll?
What is a square animation on scroll? How do you make a square animation on scroll? This script and codes were developed by Kev Rousseau on 12 August 2022, Friday.
Square animation on scroll - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Square animation on scroll</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <header><h1>Banner</h1></header>
<div class="main"> <div class="container"> <nav class="chapter toc sticky" aria-label="Document" id="chapter-toc chapter--toc"> <h1 id="table-of-contents">Table of Contents</h1> <ul id="markdown-toc"> <li><a href="#subject1">Subject 1</a></li> <li><a href="#subject2">Subject 2</a></li> <li><a href="#subject3">Subject 3</a></li> <li><a href="#subject4">Subject 4</a></li> <li><a href="#subject5">Subject 5</a></li> </ul> </nav> <section id="subject1"> <h2>Subject 1</h2> <p>The material environment draws inspiration from real-world forces, such as gravity and friction. These forces are reflected in the way user input affects elements on screen and how elements react to each other. The material environment draws inspiration from real-world forces, such as gravity and friction. These forces are reflected in the way user input affects elements on screen and how elements react to each other.</p> <p>The material environment draws inspiration from real-world forces, such as gravity and friction. These forces are reflected in the way user input affects elements on screen and how elements react to each other. The material environment draws inspiration from real-world forces, such as gravity and friction. These forces are reflected in the way user input affects elements on screen and how elements react to each other.</p> </section> <section id="subject2"> <h2>Subject 2</h2> <p>The material environment draws inspiration from real-world forces, such as gravity and friction.</p> </section> <section id="subject3"> <h2>Subject 3</h2> <p>The material environment draws inspiration from real-world forces, such as gravity and friction. These forces are reflected in the way user input affects elements on screen and how elements react to each other.</p> </section> <section id="subject4"> <h2>Subject 4</h2> <p>The material environment draws inspiration from real-world forces, such as gravity and friction. These forces are reflected in the way user input affects elements on screen and how elements react to each other.</p> <p>Forces are reflected in the way user input affects elements on screen and how elements react to each other. The material environment draws inspiration from real-world forces, such as gravity and friction. These forces are reflected in the way user input affects elements on screen and how elements react to each other.</p> </section> <section id="subject5"> <h2>Subject 5</h2> <p>The material environment draws inspiration from real-world forces, such as gravity and friction. These forces are reflected in the way user input affects elements on screen and how elements react to each other. Some pretty long text just to see how it would scroll with a super long text. Some pretty long text just to see how it would scroll with a super long text. Some pretty long text just to see how it would scroll with a super long text. Some pretty long text just to see how it would scroll with a super long text. Some pretty long text just to see how it would scroll with a super long text. Some pretty long text just to see how it would scroll with a super long text. Some pretty long text just to see how it would scroll with a super long text.</p> <p>The material environment draws inspiration from real-world forces, such as gravity and friction. These forces are reflected in the way user input affects elements on screen and how elements react to each other. Some pretty long text just to see how it would scroll with a super long text. Some pretty long text just to see how it would scroll with a super long text. Some pretty long text just to see how it would scroll with a super long text. Some pretty long text just to see how it would scroll with a super long text. Some pretty long text just to see how it would scroll with a super long text. Some pretty long text just to see how it would scroll with a super long text. Some pretty long text just to see how it would scroll with a super long text.</p> <p>The material environment draws inspiration from real-world forces, such as gravity and friction. These forces are reflected in the way user input affects elements on screen and how elements react to each other. Some pretty long text just to see how it would scroll with a super long text. Some pretty long text just to see how it would scroll with a super long text. Some pretty long text just to see how it would scroll with a super long text. Some pretty long text just to see how it would scroll with a super long text. Some pretty long text just to see how it would scroll with a super long text. Some pretty long text just to see how it would scroll with a super long text. Some pretty long text just to see how it would scroll with a super long text.</p> <p>The material environment draws inspiration from real-world forces, such as gravity and friction. These forces are reflected in the way user input affects elements on screen and how elements react to each other. Some pretty long text just to see how it would scroll with a super long text. Some pretty long text just to see how it would scroll with a super long text. Some pretty long text just to see how it would scroll with a super long text. Some pretty long text just to see how it would scroll with a super long text. Some pretty long text just to see how it would scroll with a super long text. Some pretty long text just to see how it would scroll with a super long text. Some pretty long text just to see how it would scroll with a super long text.</p> <p>The material environment draws inspiration from real-world forces, such as gravity and friction. These forces are reflected in the way user input affects elements on screen and how elements react to each other. Some pretty long text just to see how it would scroll with a super long text. Some pretty long text just to see how it would scroll with a super long text. Some pretty long text just to see how it would scroll with a super long text. Some pretty long text just to see how it would scroll with a super long text. Some pretty long text just to see how it would scroll with a super long text. Some pretty long text just to see how it would scroll with a super long text. Some pretty long text just to see how it would scroll with a super long text.</p> </section> </div>
</div>
<footer><h2>Footer</h2></footer> <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
Square animation on scroll - Script Codes CSS Codes
@import "https://fonts.googleapis.com/css?family=Roboto:400,100,100italic,300,300italic,400italic,500,500italic,700,700italic,900,900italic&subset=latin,cyrillic";
* { box-sizing: border-box;
}
body { font-family: 'RobotoDraft', 'Roboto', 'Helvetica Neue, Helvetica, Arial', sans-serif; font-size: 16px; margin: 0; font-style: normal; font-weight: 300; letter-spacing: 0.01rem; color: #212121; background-color: #f5f5f5;
}
header, footer { background-color: gray; width: 100%; height: 150px; text-align: center; display: table; box-shadow: 0px 5px 10px #ccc; z-index: 100; position: relative;
}
header h1, header h2, footer h1, footer h2 { font-size: 3em; display: table-cell; vertical-align: middle;
}
footer { box-shadow: 0px -5px 10px #ccc;
}
.toc { bottom: 0; color: #444; font-size: 0.8em; left: 0; overflow-x: hidden; overflow-y: auto; position: absolute; top: 150px; width: 25%; z-index: 10; padding-left: 20px;
}
.toc #table-of-contents { display: none;
}
.toc.sticky ul { padding: 0; position: fixed; top: 40%; -webkit-transform: translateY(-50%); -moz-transform: translateY(-50%); transform: translateY(-50%);
}
.toc.sticky ul li { list-style: none; margin-top: 20px; position: relative;
}
.toc.sticky ul li a { transition: all 0.5s ease; font-size: 1.2em; text-decoration: none; color: #222; padding: 4px; padding-left: 10px;
}
.toc.sticky ul li a:hover { color: #007d96;
}
.toc.sticky ul li a:hover:before { border-color: #11accd;
}
.toc.sticky ul li a.active { transition: all 0.5s ease; color: #007d96;
}
.toc.sticky ul li a.active:before { transition: all 0.5s ease; content: ""; top: -3px; position: absolute; z-index: 100; margin-left: -15px; width: 3px; height: calc(100% + 1 * 7px); background-color: #11accd;
}
.main { padding: 20px; padding-left: 30%;
}
section { border: 1px solid #ccc; box-shadow: 0px 2px 10px #ccc; position: relative; margin-bottom: 30px; padding: 5px 20px;
}
section:before { content: ""; top: 0px; position: absolute; z-index: 100; margin-left: -60px; width: 20px; height: 20px; background-color: #ccc; border: 2px solid #999;
}
section:after { content: ""; background: #cdcdcd; width: 2px; position: absolute; top: 0; height: calc(100% + 35px); left: -28px; z-index: 0;
}
section.active:before { content: ""; background-color: #11accd; border: 2px solid #11accd;
}
section:last-of-type { margin-bottom: 100px;
}
section:last-of-type:after { display: none;
}
Square animation on scroll - Script Codes JS Codes
function demo() { return { init: function() { this.nav = $("nav"); this.names = $("section"); }, highlight: function() { this.currentArticle = this.findCurrentArticleInVP(); // we've got the content to highlight, let's add classes and expand menu-entries var $nav = this.nav; $nav.find("a").removeClass("active"); $nav.find('a[href="#' + this.currentArticle + '"]').addClass("active"); this.names.removeClass("active"); $('section[id="' + this.currentArticle + '"]').addClass("active"); }, findCurrentArticleInVP: function() { // get the scroll height from the var viewport = $(".main")[0]; //grab the last one in case nothing is found var articleID = this.names[this.names.length - 1].id; // while our item are above the viewport, we enumerate for (var i = 0, l = this.names.length; i < l; i++) { var articleTop = this.names[i].getBoundingClientRect().top; if (isElementInViewport(viewport, this.names[i])) { //since the current element is farther, take the prev one if (i === 0) { articleID = this.names[i].id; } else { articleID = this.names[i - 1].id; } break; } } return articleID; } };
}
function isElementInViewport(viewport, el) { //special bonus for those using jQuery if (typeof jQuery === "function" && el instanceof jQuery) { el = el[0]; } var rect = el.getBoundingClientRect(); var viewportHeight = viewport.innerHeight; //100 is a subjective number. Acts like an offset to base the reaction of the highlight on. return rect.top >= 100;
}
function scrollToAnchor(aid) { var aTag = $("[id='" + aid + "']"); $("html,body").animate({ scrollTop: aTag.offset().top }, "slow");
}
var demo = new demo();
demo.init();
demo.highlight();
$(window).on("scroll", function() { demo.highlight();
});
$("nav a").on("click", function(e) { e.preventDefault(); scrollToAnchor(this.hash.substr(1)); return false;
});
Developer | Kev Rousseau |
Username | kevrousso |
Uploaded | August 12, 2022 |
Rating | 3 |
Size | 4,823 Kb |
Views | 22,264 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
CSS Collapse boxes | 2,391 Kb |
Find needle in haystack by looping through each item one by one | 2,071 Kb |
1-Discover-Backpacker | 8,202 Kb |
Faster Custom Fuzzy Search | 2,739 Kb |
Notifications | 3,496 Kb |
A Pen by Kev Rousseau | 2,186 Kb |
Square animation on scroll with instant follow | 5,023 Kb |
Fing needle in haystack by splicing array in half | 1,707 Kb |
Menu example 2 | 4,107 Kb |
Tutorial-Module | 6,953 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Coming Soon | MariamMassadeh | 1,680 Kb |
Konami Code Easter Egg | Teolitto | 3,051 Kb |
Update CSS Variables with JS | Wesbos | 2,335 Kb |
SVG Scalable Text | Said_FD | 1,451 Kb |
Vertical Pan Hammer.js example | Jtangelder | 2,144 Kb |
Flex layout example | Mofny | 1,663 Kb |
Degree Picker | Idered | 4,307 Kb |
TheCalendar.js | The-teacher | 6,330 Kb |
Falling Down the Rabbit Hole | Rachelnabors | 4,578 Kb |
Barber Shop | Bhlaird | 6,270 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!