惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Blog — PlanetScale
Blog — PlanetScale
S
Security @ Cisco Blogs
博客园 - 三生石上(FineUI控件)
博客园 - 叶小钗
Last Week in AI
Last Week in AI
Jina AI
Jina AI
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
阮一峰的网络日志
阮一峰的网络日志
GbyAI
GbyAI
Microsoft Security Blog
Microsoft Security Blog
B
Blog
A
About on SuperTechFans
B
Blog RSS Feed
M
MIT News - Artificial intelligence
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
宝玉的分享
宝玉的分享
H
Hackread – Cybersecurity News, Data Breaches, AI and More
腾讯CDC
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
H
Help Net Security
博客园 - Franky
D
Darknet – Hacking Tools, Hacker News & Cyber Security
P
Palo Alto Networks Blog
罗磊的独立博客
S
Securelist
L
LINUX DO - 热门话题
T
Tor Project blog
人人都是产品经理
人人都是产品经理
Google DeepMind News
Google DeepMind News
T
Threatpost
Simon Willison's Weblog
Simon Willison's Weblog
P
Privacy International News Feed
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Spread Privacy
Spread Privacy
WordPress大学
WordPress大学
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
MyScale Blog
MyScale Blog
T
The Blog of Author Tim Ferriss
爱范儿
爱范儿
Cyberwarzone
Cyberwarzone
NISL@THU
NISL@THU
Apple Machine Learning Research
Apple Machine Learning Research
S
SegmentFault 最新的问题
C
Cyber Attacks, Cyber Crime and Cyber Security
G
Google Developers Blog
The Hacker News
The Hacker News
Latest news
Latest news
A
Arctic Wolf
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
S
Schneier on Security

CloudCannon Blog

Building with AI: Git-based vs headless vs traditional CMS CloudCannon + Astro: performance meets powerful content management Introducing the Astro Component Starter Introducing Jetstream — built on the Astro Component Starter Why we switched to the system font stack Redesigning CloudCannon’s docs with Diátaxis, Lume, and Pagefind Make content editing more visual: upgraded Editable Regions How Configuration Mode makes building editing interfaces easy Your hosting just got an upgrade (and a price cut) Custom testing domains for professional branding Keep your content consistent with input validation Managing multilingual content in CloudCannon Simplify team publishing with conflict resolution and domain tools Open Beta: Publishing Conflict Resolution Getting started with CloudCannon and Astro: Bookshop, components, and live editing Welcome to the CloudCannon Community! Omnichannel delivery is just marketing spin from API-based CMS companies Getting started with CloudCannon and Astro: Snippets and Collections Managing digital assets in CloudCannon: a guide to smart asset storage Understanding CloudCannon's branching workflows and Projects: a complete guide What is a static website? CloudCannon’s 2024 wrapped Getting started with CloudCannon and Astro: WYSIWYG blogging Jamstack vs. WordPress: reasons to make the change The top five static site generators for 2025 (and when to use them!) Free Jekyll themes for 2025: ten great community options Eleventy (11ty) vs. Hugo How to set up WYSIWYG editing with MkDocs Material The rise of static-first websites: why major brands are making the switch Watching your Core Web Vitals on Jamstack Understanding the difference between static, dynamic, and hybrid websites Looking for an alternative to Netlify CMS or Decap CMS? Designing components for your website editors: a CloudCannon case study Does my website look big in this? Six tips to lower your page weight Content is sacred — so own your revision history The eternal balancing act: load time vs. delay time Streamlined Headless Mode, Unified Configuration, and live data editing What is a headless CMS? Looking for a TinaCMS or Tina Cloud alternative? The ultimate guide to Hugo Sections Coming soon: Live config editing and data reloading Faster publishing workflows out now! Why information architecture matters for your website Website UX vs SEO: picking your battles Easily manage your multilingual Astro site in CloudCannon How you can optimize publishing workflows for your content team How you can optimize your CMS for SEO success How you can optimize your Content Editor for long-form articles How you can optimize your Visual Editor for page building Secure, swift, and stable: static sites for the financial sector Enhanced flexibility for teams with Custom Permissions Building static sites that scale The Inaugural 11ty International Symposium on Making Web Sites Real Good How to manage hundreds of connected websites with a Git-based headless CMS How we’re building CloudCannon for accessibility CloudCannon’s new editing improvements are here! Open Beta | New ways to collaborate on editing your websites Top 11 free Eleventy themes for 2024 Top 10 free Astro themes to use in 2024 Why choose a Git-based headless CMS over a monolithic DXP in 2024? Learning web development: a self-guided roadmap Partner Site of the Month: Blüthner Piano Centre, by Winteractive CloudCannon’s 2023 wrapup Let’s create a microblog with visual editing using Bookshop and Eleventy Update and visualize your branches with CloudCannon Projects What is a Git-based CMS and why you should use one CloudCannon secures SOC 2 certification The complete guide to growing your web development agency Automatically optimize your images with Eleventy Image and CloudCannon Share components and syndicate content with Site Mounting Partner Site of the Month: Cru Uncorked, by Ed Meehan New web component for responsive HTML tables Wrapping up HugoConf 2023 Partner Site of the Month: Van Dillen Antieke Bouwmaterialen, by Fulldev How to become a freelance web developer: a comprehensive guide Q3 2023: CloudCannon features and improvements 22 ways to deliver more value to your web development clients Partner Site of the Month: DC Gay Flag Football League, by Ed Cupaioli A new way to configure your CloudCannon sites CloudCannon — the official CMS partner of Eleventy Full CloudCannon support for Nuxt static sites Partner Site of the Month: Stadium Bike, by Insight Creative, Inc. HugoConf 2023, brought to you by CloudCannon DAM Support for Cloudflare R2 and DigitalOcean Spaces Eleventy (11ty) vs. Gatsby in 2023 – which SSG is best for you? How CloudCannon’s live editing works with Astro and Bookshop Partner Site of the Month: Fiducian, by Croissant & Baguette Eleventy (11ty) vs. Astro How to customize CloudCannon’s Client Sharing interface Let anyone, anywhere, edit your CloudCannon sites Top 23 free Astro themes for building out-of-this-world static sites in 2023 How Jampack optimizes our Eleventy website and improves performance Astro vs. Next.js CloudCannon.com is now built with Eleventy! Out-of-this-world support for all Astro users Introducing the CloudCannon Partner Program Full CloudCannon support for Gatsby Top 10 Free SvelteKit Themes for Building Lighting-Fast Static Sites in 2023 Enhanced CloudCannon support for Next.js users Upcoming CloudCannon Interface improvements (Open Beta)
How to create an animated pickup in CSS and HTML
2014-12-19 · via CloudCannon Blog

This week I came across the 7mml website and I loved the loaded symbol. An animated car with a scrolling background. It was rather sluggish so I looked at how it was built. It was actually built using a large background image with JavaScript changing the background position.

What is it? Direct link to this section

I am going to rebuild the car/pickup in HTML, SVG and CSS. I was going to build it all in CSS but as it is a complicated shape SVG is probably better. Here's my version:

illustration of white truck used for animating

illustration of white truck frame used for animating

<div class="truck">
<div class="body">
<img src="truck-under.svg">
<div class="shine"></div>
<img src="truck-frame.svg" class="frame">
</div>

<div class="speed-thingy"></div>
<div class="speed-thingy second"></div>
<div class="shadow"></div>

<div class="wheel back"></div>
<div class="wheel front"></div>
</div>

Let's break it down.

The Wheels Direct link to this section

I started building the car using just HTML and CSS so theses are circles built using border-radius. I used the :before and :after pseudo-elements too for the inner circles. You may be asking "Why did you not use a border on the inner circle?" - if I used border I would not be able to use percentage widths. Then I added an infinite spin animation which works well because of the slightly inconsistent size;

illustration of white truck frame used for animating

@keyframes spin {
0% { transform: rotate(0); }
100% { transform: rotate(360deg); }
}

.wheel,
.wheel:after,
.wheel:before
{
bottom: -20%;
width: 12.8%;
height: 46.38%;
border-radius: 100%;
background: #1e2327;
}

.wheel {
left: 21.5%;
-webkit-animation: spin 0.4s infinite linear;
animation: spin 0.4s infinite linear;
}

.wheel.front {
left: 82%;
}

.wheel:after,
.wheel:before
{
content: "";
position: absolute;
display: block;
top: 20%;
left: 20%;
width: 60%;
height: 60%;
}

.wheel:before {
background: #aaa;
}

.wheel:after {
top: 40%;
left: 40%;
width: 20%;
height: 20%;
}

The Body Direct link to this section

I started building the body with HTML elements and CSS but felt I was using the wrong tool for the job. I decided to use SVG instead. There are actually two assets to be exact and I overlay one on the other with a slight rotation and vertical transition to give it a bit of character.

illustration of white truck used for animating

illustration of white truck frame used for animating

@keyframes bobbing {
0%{
transform: rotate(0) translateY(0);
}
100%{
transform: rotate(0.1deg) translateY(5px);
}
}

.body {
width: 100%;
position: relative;
transform-origin: right center;
animation: bobbing 0.2s infinite ease-in-out forwards alternate;
}

.frame {
position: relative;
}

.truck img {
width: 100%;
height: auto;
top: 0;
left: 0;
margin: 0;
}

The Shine Direct link to this section

This uses the same effect as the Facebook content placeholder. It has the bobble animation as it's placed inside the .body of the truck. The first image is to show the gradient and the shape which is achieved using transforms and a linear gradient. The second one has an animation applied.

@keyframes shine {
0%{
opacity: 0.1;
background-position: 50px top;
}
30% { opacity: 1; }
50%, 100%{
opacity: 0.2;
background-position: -500px 0;
}
}

.shine {
/* Position it in the gap */
width: 67%;
height: 37%;
left: 9%;
top: 6%;

/* Shape of the div to fit the windows */
transform: skew(33deg, 1deg);
border-radius: 56px 100px 20px 0;

/* The background */
background: linear-gradient(to right, transparent 76%, rgba(255,255,255,0.8) 78%, rgba(255,255,255,0.8) 96%, transparent 98%);
background-repeat: no-repeat;
background-size: cover;

/* The animation */
animation: shine 3s infinite ease forwards;
}

The Speed Things Direct link to this section

These are simple shrinking and growing divs.

illustration of white truck frame used for animating

@keyframes thingy {
0%{
transform: translateX(0);
width: 0;
opacity: 0;
}
10%{
width: 10%;
opacity: 1;
}
30%, 100%{
transform: translateX(-250px);
width: 0;
opacity: 0;
}
}

.speed-thingy {
position: absolute;
width: 20px;
border-radius: 10px;
height: 5%;
background: #fff;
top: -10%;
left: 50%;
animation: thingy 3s infinite ease forwards;
}

.speed-thingy.second {
top: 50%;
left: 30%;
animation-delay: 0.1s;
}

A Shadow to top it all off Direct link to this section

This makes the bobbing effect seem more realistic and shows a platform for the wheels to sit on. We want it to stay still at the front so we change the transform origin to the front. Once that's done we scale it ever so slightly with timing to match the body.

<img src="https://cc-dam.imgix.net/blog/assets/blog/assets/blog/truck-frame.svg"alt="illustration of white truck frame used for animating" width="500" height="136" class="frame">

@keyframes shadow {
0%{
transform: scale(1);
}
100%{
transform: scale(1.01);
}
}

.shadow {
width: 90%;
border-radius: 100%;
height: 20px;
bottom: -25%;
left: 5%;
background: rgba(0,0,0,0.1);
animation: shadow 0.2s infinite ease-in-out forwards alternate;
transform-origin: right center;
}

All Together Again Direct link to this section

illustration of white truck used for animating

<img src="/assets/blog/truck-frame.svg"alt="illustration of white truck frame used for animating" width="500" height="136" class="frame">

Why would I ever use this? Direct link to this section

Using CSS animations rather than sprite sheets will give you:

  • A crisp look on all screen resolutions
  • Seamless tweening between states.
  • Flexibility to reuse work (It's much easier to change code then recreate assets)

That's it Direct link to this section

I have altered the original quite a bit and the key with these animations was subtlety. Each part adds up to a make it look like it is traveling forward even without the background animations. Going back to Tim's one word idea, for animations it would be to "subtlety" or "reactive". Animations should not surprise the user, they should feel natural and help convey a real world metaphor. If an animation is off continued use will annoy the user not improve their experience. Hope you enjoyed this deconstruction, comment below if you have any questions.