search
HomeWeb Front-endCSS TutorialSlide Through Unlimited Dimensions With CSS Scroll Timelines

Slide Through Unlimited Dimensions With CSS Scroll Timelines

The original design philosophy of CSS, whose creators had imagined that it would become the main technology for web behavior control, and scripting languages ​​are only an alternative when CSS cannot implement functions declaratively. This methodology of priority use of CSS is based on the concept that "scripts are programming, but programming is difficult". Since the introduction of the :hover pseudo-class, CSS has been standardizing patterns created by developers in JavaScript and "included" them into the CSS standard. From this perspective, JavaScript is almost like a "workaround", and CSS is the official approach.

Therefore, using CSS to implement script-like behavior makes us feel less "awkish", and it is no surprise that features like the new scroll-timeline feature appear. Many developers implement clever parallax scrolling websites, which prevents us from putting this CSS feature "sprite" back into the bottle. If you don't want the stuttering main thread animation in the next parallax scrolling site, you must now turn to the "dark side" of CSS hackers. (Just kidding), if you prefer imperative programming, there is also a new JavaScript API for scrolling association animations.

Migrate JavaScript examples to CSS

Modify the parallax scroll animation example before Chris Coyier, replace the CSS used by Chris to control the animation with a line of scroll-timeline CSS code, and completely remove the JavaScript code, which is satisfactorily simple.

Using the
body, .progress, .cube {
  animation-timeline: scroll();
}
function without parameters will set an "anonymous scrolling progress timeline", which means that if our writing mode is in English, the browser will animate based on the recent ancestor elements that can scroll vertically. Unfortunately, it would be very useful to have only a choice to animate based on scrolling on the x-axis or y-axis of a particular element, not both. As a function we can pass parameters to

which gives better control over how we want the scroll to run the animation. scroll() scroll()Multi-dimensional experiment

Better is the

attribute. Applying it to a container element means we can animate the attributes on any selected ancestor element based on any scrollable element with the same assigned scope. This got me thinking... Since CSS Houdini allows us to register animation-friendly, inheritable properties in CSS, we can combine animations on the same element based on multiple scrollable areas on the page. This opens the door to interesting teaching design possibilities, such as my experiment below.

Scrolling the horizontal narrative on the light green card will rotate the 3D NES console horizontally, and scrolling the vertical narrative on the dark green card will rotate the NES console vertically. In my previous post, I mentioned that my past CSS tricks always boil down to the possibility of hiding and showing limited possibilities with CSS. What I'm interested in this roll-based experiment is the combination explosion of vertical and horizontal rotations of combinations. Animated timelines provide pure CSS interactivity that was impossible in the past.

Implementation details are not as important as timeline-scope's use and custom properties. We register two custom angle properties:

body, .progress, .cube {
  animation-timeline: scroll();
}

Then we "borrow" NES 3D models from the examples in Julian Garner's amazing CSS 3D modeling application. We update the .scene class to make 3D rotation based on our new variables as follows:

@property --my-y-angle {
  syntax: "<angle>";
  inherits: true;
  initial-value: 0deg;
}

@property --my-x-angle {
  syntax: "<angle>";
  inherits: true;
  initial-value: -35deg;
}</angle></angle>

Next, we provide a body element with two custom named scopes. scroll-scope

.scene {
  transform: rotateY(var(--my-y-angle)) rotateX(var(--my-x-angle));
}
I don't see any official documentation on passing in multiple scopes, but it does work in Google Chrome and Edge. If it's not a formally supported feature, I hope it will be part of the standard as it's very convenient.

Next, we define the named timeline for the two scrollable cards and the axis we want to trigger the animation.

body {
  scroll-scope: --myScroller,--myScroller2; 
}
and add the animation to the scene:

.card:first-child {
  scroll-timeline-axis: x;
  scroll-timeline-name: --myScroller;
}

.card:nth-child(2) {
  scroll-timeline-axis: y;
  scroll-timeline-name: --myScroller2;
}
Since the 3D model inherits the x and y angles of the document body, the scrolling card now rotates the model in a combination of vertical and horizontal angle changes.

User control animation beyond scrollbar

Think about it carefully, this behavior is not only useful for scroll-driven animations. In the above experiment, we use the scrollable area more as a slider to control the properties of the 3D model. After finishing my work, I went out for a walk and fantasized how cool it would be if the actual range input could control the animation timeline. Then I found that they can! At least in Chrome. Pure CSS CMS?

While we requisitioned the 3D model from Julian Garner, let's see if we can use range input to control his X-wing model.

Incredible that we can do this by simply using CSS, and we can do it with any number of properties. For me, that's not enough. I would like to see other input controls that can manipulate the animation timeline. Imagine that the text field pushes the animation as you fill it in, or that the button can play or reverse the animation. The latter can be implemented to some extent by combining the

pseudo-class with the :active attributes. But in my experience, the browser may be confused when you try to use it to animate multiple custom properties. In contrast, the animation timeline was designed with this use case in mind, so it ran smoothly and exactly what I expected. animation-play-state

I'm not the only one who noticed the potential of this emerging CSS feature. Someone has implemented this clever Doom clone by combining scroll-timeline and checkbox tricks. My problem is that it is still not enough. We have enough resources in Chrome to implement the avatar builder using scrollbars and range inputs as game controls. I am happy to try an unpredictable, complex experience that was unprecedented in the era before the appearance of the scroll-timeline features. After all, if you have to explain the definition of video games to aliens, wouldn't you say it's just a super interactive animation?

The above is the detailed content of Slide Through Unlimited Dimensions With CSS Scroll Timelines. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
What is CSS Grid?What is CSS Grid?Apr 30, 2025 pm 03:21 PM

CSS Grid is a powerful tool for creating complex, responsive web layouts. It simplifies design, improves accessibility, and offers more control than older methods.

What is CSS flexbox?What is CSS flexbox?Apr 30, 2025 pm 03:20 PM

Article discusses CSS Flexbox, a layout method for efficient alignment and distribution of space in responsive designs. It explains Flexbox usage, compares it with CSS Grid, and details browser support.

How can we make our website responsive using CSS?How can we make our website responsive using CSS?Apr 30, 2025 pm 03:19 PM

The article discusses techniques for creating responsive websites using CSS, including viewport meta tags, flexible grids, fluid media, media queries, and relative units. It also covers using CSS Grid and Flexbox together and recommends CSS framework

What does the CSS box-sizing property do?What does the CSS box-sizing property do?Apr 30, 2025 pm 03:18 PM

The article discusses the CSS box-sizing property, which controls how element dimensions are calculated. It explains values like content-box, border-box, and padding-box, and their impact on layout design and form alignment.

How can we animate using CSS?How can we animate using CSS?Apr 30, 2025 pm 03:17 PM

Article discusses creating animations using CSS, key properties, and combining with JavaScript. Main issue is browser compatibility.

Can we add 3D transformations to our project using CSS?Can we add 3D transformations to our project using CSS?Apr 30, 2025 pm 03:16 PM

Article discusses using CSS for 3D transformations, key properties, browser compatibility, and performance considerations for web projects.(Character count: 159)

How can we add gradients in CSS?How can we add gradients in CSS?Apr 30, 2025 pm 03:15 PM

The article discusses using CSS gradients (linear, radial, repeating) to enhance website visuals, adding depth, focus, and modern aesthetics.

What are pseudo-elements in CSS?What are pseudo-elements in CSS?Apr 30, 2025 pm 03:14 PM

Article discusses pseudo-elements in CSS, their use in enhancing HTML styling, and differences from pseudo-classes. Provides practical examples.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft