This repository has been archived on 2022-03-12. You can view files and clone it, but cannot push or open issues or pull requests.
reValuate/logo-test.html

171 lines
7.4 KiB
HTML
Raw Normal View History

2021-09-12 20:39:15 +03:00
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>logo test</title>
<style style="text/css">
html, body {margin: 0; padding: 0;}
body { background-color: #93C900; }
#revaluate_logo {
transform: rotate3d(1, 1, 0.3, 20deg) translateZ(100px) translateY(22px);
max-width: 10vw;
filter: drop-shadow(3px -3px 0 rgba(0, 0, 0, .3));
}
#revaluate_logo path {
fill: white;
}
#revaluate_logo .arrows {
transform-origin: center;
}
body > header {
padding-top: 1vw;
position: sticky;
top: 0;
background-color: rgb(203, 125, 255);
}
</style>
<script type="text/javascript">
function rotateLogo(elem) {
elem.style.transform = "rotate(" + window.scrollY/20 + "deg)";
}
window.addEventListener('load', function main() {
window.addEventListener("scroll", rotateLogo.bind(null,
document.querySelector('#revaluate_logo .arrows')));
});
</script>
</head>
<body>
<header>
<svg version="1.1" id="revaluate_logo" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px"
y="0px" viewBox="0 0 1100 1100" style="enable-background:new 0 0 1100 1100;" xml:space="preserve">
<path class="arrows" d="M452.35,911.88l-19.16,84.87c-96.46-21.78-182.42-71.91-248.57-144.97c-31.84-35.17-58.24-74.78-78.46-117.73
c-16.77-35.63-29.01-73.01-36.54-111.44l-65.61-0.89L115,435.4l105.9,189.27l-61.96-0.84c15.38,62.9,46.13,120.91,90.17,169.56
C303.17,853.1,373.46,894.07,452.35,911.88z M999.22,406.1l-83.97,22.75c21.15,78.06,17.79,159.35-9.7,235.06
c-22.4,61.68-59.3,115.99-107.71,159l-28.23-55.16L651.83,949.88l216.6,10.97l-29.89-58.41c30.45-24.62,57.76-52.93,81.41-84.41
c28.51-37.95,51.18-79.81,67.37-124.4C1020.97,600.97,1025.08,501.55,999.22,406.1z M833.45,212.74L727.97,23.24l-33.69,56.3
c-37.02-12.77-75.5-20.94-114.73-24.31c-47.29-4.07-94.8-1.11-141.2,8.79c-96.4,20.56-182.89,69.76-250.13,142.27l63.79,59.16
c54.99-59.3,125.71-99.53,204.49-116.34c64.18-13.69,129.79-11.17,191.91,7.09l-31.82,53.18L833.45,212.74z"/>
<path d="M747.7,705.9H620.8L590,636.4c-11.3-25.4-21.5-44-30.5-55.8c-9-11.8-17.9-19.3-26.4-22.6c-8.6-3.3-19.6-5-33.2-5h-13.3
v152.9H368.3V314.1h201c32.4,0,59,6.6,79.7,19.8s35.7,29.2,44.8,48.1c9.1,18.9,13.7,36.8,13.7,53.7c0,19.8-3.8,36.5-11.5,50.2
c-7.6,13.7-15.7,23.6-24.2,29.8s-18,12.2-28.5,17.8c12.6,7.3,23,16.1,31.2,26.2s19.4,30.5,33.5,61.2L747.7,705.9z M587.1,437.9
c0-18.1-5.9-30.7-17.8-37.9s-31.2-10.7-57.9-10.7h-24.9v94.4h25.4c28.8,0,48.6-3.1,59.2-9.5C581.8,467.9,587.1,455.8,587.1,437.9z"
/>
</svg>
</header>
<pre style="width: 20vw; white-space: pre-wrap;">
the new code
Im Dudley Storey, author of Using SVG with CSS3 and HTML5, Smashing Magazine contributing editor, teacher and speaker. I write about all aspects of web development, including:
HTML
CSS
JavaScript
SVG
Responsive Design
Galleries
PHP
MySQL
SEO
Accessibility
Servers & Hosting
Business
Exercises & Quizzes
To receive more information, including news, updates, and tips, follow me on Twitter or add me on Google+.
Become a Patron
This site helps millions of visitors while remaining ad-free. For less than the price of a cup of coffee, you can help pay for bandwidth and server costs while encouraging further articles.
projects
The New DefaultsA Sass color keyword system for designers. Replaces CSS defaults with improved hues and more memorable, relevant color names.
CSSslidyAn auto-generated #RWD image slider. 3.8K of JS, no JQuery. Drop in images, add a line of CSS. Done.
Massive Head CanonMassive Head Canon. Intelligent discussion of movies, books, games, and technology.
books
Pro CSS Animation (Apress, 2013)
Animation Fundamentals: Understanding Particles Mesh Animation with HTML5 Canvas Scrolling SVG Sunset
Part of the Scrolling Effects Reading List
Rotate Elements on Scroll with JavaScript
Updated 5 years ago
Share onTwitterFacebookGoogle+
When I recoded and rebranded this site four months ago, I decided to make it completely free of frameworks: while the text and visible code samples for JQuery articles often remained unchanged, under the hood everything had to run vanilla JavaScript.
One of those articles explored how to rotate elements on the page with scroll. This article presents an updated version using the code that actually runs underneath that demo, written in vanilla JavaScript… in many respects, an approach that is simpler and more efficient.
Setting The Gears
As with the previous example, the gears are placed on the page using separate id values. Since they are vector shapes, it makes sense to build and reference the gears as SVG images:
There are many possibilities for positioning the gears: very often they will have a fixed position on the page; its also possible to use the new CSS “scroll-to-top-then-fixed” positioning (aka position: sticky). In this example, Ive used flexbox to separate the elements, and vw units to size them; otherwise, the gears use standard static positioning, and therefore completely scroll with the page.
#gearbox {
display: flex;
justify-content: space-between;
}
#leftgear, #rightgear {
width: 20vw;
max-width: 20%;
height: auto;
}
Rotating the Gears
Rotating the elements themselves is quite straightforward: at the bottom of the page, add the following script.
var leftgear = document.getElementById("leftgear"),
rightgear = document.getElementById("rightgear");
window.addEventListener("scroll", function() {
leftgear.style.transform = "rotate("+window.pageYOffset+"deg)";
rightgear.style.transform = "rotate(-"+window.pageYOffset+"deg)";
});
Each gear rotates by the amount the window is scrolled in pixels, converted into degrees, the left gear rotating clockwise, and the right counter-clockwise. To speed up or slow down the rotation relative to the amount of scrolling, you could make window.pageYOffset part of a simple mathematical expression: multiplying or dividing it by 2, for example.
Avoid Grinding Your Gears
A common issue with any technique that manipulates scroll behaviour is “janking”: elements stuttering as they try to match user input with the browsers repaint cycle. The easiest way to deal with this is to only move the elements when the browser is prepared to do so, via requestAnimationFrame. To do so, the addEventListener changes to listen for a custom event:
window.addEventListener("optimizedScroll", function() {
})
Above the event handler, add an anonymous function:
;(function() {
var throttle = function(type, name, obj) {
var obj = obj || window;
var running = false;
var func = function() {
if (running) { return; }
running = true;
requestAnimationFrame(function() {
obj.dispatchEvent(new CustomEvent(name));
running = false;
});
};
obj.addEventListener(type, func);
};
throttle ("scroll", "optimizedScroll");
})();
Ill have much more to say about requestAnimationFrame in coming articles.
Enjoy this piece? I invite you to follow me at twitter.com/dudleystorey to learn more.
Check out the CodePen demo for this article at https://codepen.io/dudleystorey/pen/pgzeor
Scroll-to-Focus Effect For Hero Images
Background Reveal Scroll In Pure CSS
</pre>
</body>
</html>