DEV Community

Cover image for Flight Slider in HTML + CSS
Alvaro Montoro
Alvaro Montoro

Posted on

Flight Slider in HTML + CSS

Last week, I created an input range that looks like a plane flying to its destination (move the plane right and left):

I tried to add as many details as possible while keeping the code simple and independent of external resources (JavaScript or images):

  • It uses a single HTML element (an input range, although it should be a <progress>)
  • It includes a single JS command to update a CSS variable
  • The plane takes off and lands using trigonometric functions
  • Using container queries, the plane changes into a helicopter in smaller sizes (although I wouldn't recommend it to go from NYC to Madrid)
  • Both the plane and helo are CSS art, not SVG (again with the independence of external resources... although I'll admit it would look better with SVG)
  • It has printing styles
  • It was coded with accessibility in mind (although it may not be perfect): works with a keyboard and also in high-contrast mode
  • It will work in all modern browsers

Any feedback? I will write an article this weekend with more details on how it was coded. Anything you'd like me to include about the code or the process?

Top comments (22)

Collapse
 
schemetastic profile image
Schemetastic (Rodrigo)

I'd like the scale oscillation it has when moving from 0 to 0.5 and then 1, great trick with the shadow too.

Collapse
 
alvaromontoro profile image
Alvaro Montoro • Edited

That's where I used the trigonometry functions: sin(0) = 0, sin(Ο€/2) = 1, and sin(Ο€) = 0. So I used the range value to calculate the scale multiplying by pi.

The same trick was used for the shadow: farther and lighter at the middle part, and closer and darker at the edges.

Collapse
 
schemetastic profile image
Schemetastic (Rodrigo) • Edited

Wow! That's really cool! You know, me I'm different, haha. I would probably have used a base64 SVG for the plane, a shadow filter (for the shadow obviously), and create a function in JS to generate the oscillation and assign it to a custom property. But I would hardly have thought an almost pure CSS solution for that. I checked your YouTube channel and website, keep doing what you love.

Have you considered creating beautiful layouts and components? I'm pretty sure that with your skills, you can create things that standout and that other devs would love to follow along you in your tutorials to create stuff for their portfolios and websites, just a suggestion.

Thread Thread
 
alvaromontoro profile image
Alvaro Montoro

Thank you. To be fair, using SVG and JavaScript with this component –even if only one more line than what I added–, could improve the experience considerably. About the components... Maybe I could try?

Thread Thread
 
schemetastic profile image
Schemetastic (Rodrigo)

Well, haha, it was just a suggestion... I mean, is what I personally thought it could help you to get more audience, because you have an hability that not everyone has.

You know, just yesterday I uploaded a redesign of my portfolio website, in it I used oscillation in elements that scale according to the scroll, I already had that but your plane shadow slider inspired me to add some glows that oscillate too You can check it if you want to, I used JS to generate the value but the styles are handle with CSS vars and calc.

Thread Thread
 
greenteaisgreat profile image
Nathan G Bornstein

Any time I see folks doing pure CSS solutions when they could've easily chosen another tech to make their life that much easier, I have to give credit where its due. That's such a zen approach and honestly, such a flex. It's impressive as heck.

Also, @schemetastic, sick portfolio! That has so much charm and personality to it

Thread Thread
 
schemetastic profile image
Schemetastic (Rodrigo) • Edited

Thanks Nathan! It was a lot of hard work, I hope one day it pays off.

Interesting music you have there by the way, haha.

Thread Thread
 
greenteaisgreat profile image
Nathan G Bornstein

Hahaha, my one true motive for being on this platform: promoting my crappy folk punk band 😈

Thread Thread
 
schemetastic profile image
Schemetastic (Rodrigo)

Well... is working then, hahaπŸ˜‚

β€œDepression is One Hell of a Drug (Imbalance)” seems pretty deep, and yes, negative thoughts are addictive I've experienced that many times! But once you embrace positive thoughts they become addictive too, but they require more efforts to produce.

Collapse
 
sreno77 profile image
Scott Reno

Very cool demo!

Collapse
 
alvaromontoro profile image
Alvaro Montoro

Thanks!

Collapse
 
piko profile image
Piko

I freaking love it!

Collapse
 
teaganga profile image
teaganga

Looks really nice!

Collapse
 
ritirathod0 profile image
Riti Rathod

Great

Collapse
 
aroldev profile image
Arol

The trigonometry functions just blow my mind... That's amazing, Álvaro!!!

Collapse
 
blenderman profile image
BBM

This is really cool

Collapse
 
pandeyaditya0002 profile image
Aditya Pandey

This is really cool

Collapse
 
best_codes profile image
Best Codes

Nice job! I'd like to suggest that you add outline: none to the input to remove the outline, as it does look a bit strange.

Image description

Otherwise, it's awesome!

Collapse
 
alvaromontoro profile image
Alvaro Montoro

Thank you! About the outline, I cannot remove outline: none because it would be an accessibility issue... but it does look a bit weird. Maybe I could reduce it to just the airplane? Or the bar but not the airplane?

Collapse
 
best_codes profile image
Best Codes

Oh, I see! Perhaps the bar only would look better. I'm not very good at making style changes, though. Do what you think is best. Again, awesome project!

Collapse
 
mardeg profile image
Mardeg

Love it! All that CSS to create a ✈️ and 🚁 when I would've just used an emoji rotated to point them in the right direction.

Some comments may only be visible to logged-in visitors. Sign in to view all comments.