Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      Sunshine And March Vibes (2025 Wallpapers Edition)

      June 1, 2025

      The Case For Minimal WordPress Setups: A Contrarian View On Theme Frameworks

      June 1, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      June 1, 2025

      How To Prevent WordPress SQL Injection Attacks

      June 1, 2025

      7 MagSafe accessories that I recommend every iPhone user should have

      June 1, 2025

      I replaced my Kindle with an iPad Mini as my ebook reader – 8 reasons why I don’t regret it

      June 1, 2025

      Windows 11 version 25H2: Everything you need to know about Microsoft’s next OS release

      May 31, 2025

      Elden Ring Nightreign already has a duos Seamless Co-op mod from the creator of the beloved original, and it’ll be “expanded on in the future”

      May 31, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      Student Record Android App using SQLite

      June 1, 2025
      Recent

      Student Record Android App using SQLite

      June 1, 2025

      When Array uses less memory than Uint8Array (in V8)

      June 1, 2025

      Laravel 12 Starter Kits: Definite Guide Which to Choose

      June 1, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      Photobooth is photobooth software for the Raspberry Pi and PC

      June 1, 2025
      Recent

      Photobooth is photobooth software for the Raspberry Pi and PC

      June 1, 2025

      Le notizie minori del mondo GNU/Linux e dintorni della settimana nr 22/2025

      June 1, 2025

      Rilasciata PorteuX 2.1: Novità e Approfondimenti sulla Distribuzione GNU/Linux Portatile Basata su Slackware

      June 1, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»News & Updates»Web-Slinger.css: Across the Swiper-Verse

    Web-Slinger.css: Across the Swiper-Verse

    January 15, 2025

    My previous article warned that horizontal motion on Tinder has irreversible consequences. I’ll save venting on that topic for a different blog, but at first glance, swipe-based navigation seems like it could be a job for Web-Slinger.css, your friendly neighborhood experimental pure CSS Wow.js replacement for one-way scroll-triggered animations. I haven’t managed to fit that description into a theme song yet, but I’m working on it.

    In the meantime, can Web-Slinger.css swing a pure CSS Tinder-style swiping interaction to indicate liking or disliking an element? More importantly, will this experiment give me an excuse to use an image of Spider Pig, in response to popular demand in the bustling comments section of my previous article? Behold the Spider Pig swiper, which I propose as a replacement for captchas because every human with a pulse loves Spider Pig. With that unbiased statement in mind, swipe left or right below (only Chrome and Edge for now) to reveal a counter showing how many people share your stance on Spider Pig.

    CodePen Embed Fallback

    Broaden your horizons

    The crackpot who invented Web-Slinger.css seems not to have considered horizontal scrolling, but we can patch that maniac’s monstrous creation like so:

    [class^="scroll-trigger-"] {
      view-timeline-axis: x;
    }

    This overrides the default behavior for marker elements with class names using the Web-Slinger convention of scroll-trigger-n, which activates one-way, scroll-triggered animations. By setting the timeline axis to x, the scroll triggers only run when they are revealed by scrolling horizontally rather than vertically (which is the default). Otherwise, the triggers would run straightaway because although they are out of view due to the container’s width, they will all be above the fold vertically when we implement our swiper.

    My steps in laying the foundation for the above demo were to fork this awesome JavaScript demo of Tinder-style swiping by Nikolay Talanov, strip out the JavaScript and all the cards except for one, then import Web-Slinger.css and introduce the horizontal patch explained above. Next, I changed the card’s container to position: fixed, and introduced three scroll-snapping boxes side-by-side, each the height and width of the viewport. I set the middle slide to scroll-align: center so that the user starts in the middle of the page and has the option to scroll backwards or forwards.

    Sidenote: When unconventionally using scroll-driven animations like this, a good mindset is that the scrollable element needn’t be responsible for conventionally scrolling anything visible on the page. This approach is reminiscent of how the first thing you do when using checkbox hacks is hide the checkbox and make the label look like something else. We leverage the CSS-driven behaviors of a scrollable element, but we don’t need the default UI behavior.

    I put a div marked with scroll-trigger-1 on the third slide and used it to activate a rejection animation on the card like this:

    <div class="demo__card on-scroll-trigger-1 reject">
      <!-- HTML for the card -->
    </div>
    
    <main>
      <div class="slide">
      </div>
      <div id="middle" class="slide">
      </div>
      <div class="slide">
          <div class="scroll-trigger-1"></div>
      </div>
    </main>

    It worked the way I expected! I knew this would be easy! (Narrator: it isn’t, you’ll see why next.)

    <div class="on-scroll-trigger-2 accept">
      <div class="demo__card on-scroll-trigger-2 reject">
      <!-- HTML for the card -->
      </div>
    </div>
    
    <main>
      <div class="slide">
          <div class="scroll-trigger-2"></div>
      </div>
      <div id="middle" class="slide">
      </div>
      <div class="slide">
          <div class="scroll-trigger-1"></div>
      </div>
    </main>

    After adding this, Spider Pig is automatically ”liked” when the page loads. That would be appropriate for a card that shows a person like myself who everybody automatically likes — after all, a middle-aged guy who spends his days and nights hacking CSS is quite a catch. By contrast, it is possible Spider Pig isn’t everyone’s cup of tea. So, let’s understand why the swipe right implementation would behave differently than the swipe left implementation when we thought we applied the same principles to both implementations.

    Take a step back

    This bug drove home to me what view-timeline does and doesn’t do. The lunatic creator of Web-Slinger.css relied on tech that wasn’t made for animations which run only when the user scrolls backwards.

    This visualizer shows that no matter what options you choose for animation-range, the subject wants to complete its animation after it has crossed the viewport in the scrolling direction — which is exactly what we do not want to happen in this particular case.

    Fortunately, our friendly neighborhood Bramus from the Chrome Developer Team has a cool demo showing how to detect scroll direction in CSS. Using the clever --scroll-direction CSS custom property Bramus made, we can ensure Spider Pig animates at the right time rather than on load. The trick is to control the appearance of .scroll-trigger-2 using a style query like this:

    :root {
      animation: adjust-slide-index 3s steps(3, end), adjust-pos 1s;
      animation-timeline: scroll(root x);
    }
    @property --slide-index {
      syntax: "<number>";
      inherits: true;
      initial-value: 0;
    }
    
    @keyframes adjust-slide-index {
      to {
        --slide-index: 3;
      }
    }
    
    .scroll-trigger-2  {
      display: none;
    }
    
    @container style(--scroll-direction: -1) and style(--slide-index: 0) {
      .scroll-trigger-2 {
        display: block;
      }
    }

    That style query means that the marker with the .scroll-trigger-2 class will not be rendered until we are on the previous slide and reach it by scrolling backward. Notice that we also introduced another variable named --slide-index, which is controlled by a three-second scroll-driven animation with three steps. It counts the slide we are on, and it is used because we want the user to swipe decisively to activate the dislike animation. We don’t want just any slight breeze to trigger a dislike.

    When the swipe has been concluded, one more like (I’m superhuman)

    As mentioned at the outset, measuring how many CSS-Tricks readers dislike Spider Pig versus how many have a soul is important. To capture this crucial stat, I’m using a third-party counter image as a background for the card underneath the Spider Pig card. It is third-party, but hopefully, it will always work because the website looks like it has survived since the dawn of the internet. I shouldn’t complain because the price is right. I chose the least 1990s-looking counter and used it like this:

    @container style(--scroll-trigger-1: 1) {
      .result {
        background-image: url('https://counter6.optistats.ovh/private/freecounterstat.php?c=qbgw71kxx1stgsf5shmwrb2aflk5wecz');
        background-repeat: no-repeat;
        background-attachment: fixed;
        background-position: center;
      }
    
      .counter-description::after {
        content: 'who like spider pig';
      }
    
      .scroll-trigger-2 {
        display: none;
      }
    }
    
    @container style(--scroll-trigger-2: 1) {
      .result {
        background-image: url('https://counter6.optistats.ovh/private/freecounterstat.php?c=abtwsn99snah6wq42nhnsmbp6pxbrwtj');
        background-repeat: no-repeat;
        background-attachment: fixed;
        background-position: center;
      }
    
      .counter-description::after {
        content: 'who dislike spider pig';
      }
    
      .scroll-trigger-1 {
        display: none;
      }
    }

    Scrolls of wisdom: Lessons learned

    This hack turned out more complex than I expected, mostly because of the complexity of using scroll-triggered animations that only run when you meet an element by scrolling backward which goes against assumptions made by the current API. That’s a good thing to know and understand. Still, it’s amazing how much power is hidden in the current spec. We can style things based on extremely specific scrolling behaviors if we believe in ourselves. The current API had to be hacked to unlock that power, but I wish we could do something like:

    [class^="scroll-trigger-"] {
      view-timeline-axis: x;
      view-timeline-direction: backwards; /* <-- this is speculative. do not use! */
    }

    With an API like that allowing the swipe-right scroll trigger to behave the way I originally imagined, the Spider Pig swiper would not require hacking.

    I dream of wider browser support for scroll-driven animations. But I hope to see the spec evolve to give us more flexibility to encourage designers to build nonlinear storytelling into the experiences they create. If not, once animation timelines land in more browsers, it might be time to make Web-Slinger.css more complete and production-ready, to make the more advanced scrolling use cases accessible to the average CSS user.


    Web-Slinger.css: Across the Swiper-Verse originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

    Source: Read More 

    Hostinger
    Facebook Twitter Reddit Email Copy Link
    Previous ArticleAmazon AGI lead says “several technical hurdles” delay revamped Alexa release: “Hallucinations have to be close to zero”
    Next Article Daisy – general-purpose TUI scientific calculator

    Related Posts

    News & Updates

    7 MagSafe accessories that I recommend every iPhone user should have

    June 1, 2025
    News & Updates

    I replaced my Kindle with an iPad Mini as my ebook reader – 8 reasons why I don’t regret it

    June 1, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    Learn Relational Database Basics – Key Concepts for Beginners

    Development

    Sam Altman wants OpenAI to be the Microsoft of AI, with a subscription-based operating system built on ChatGPT

    News & Updates

    Microsoft CEO Satya Nadella claimed Google fumbled its AI opportunity — but DeepMind is already hiring for a post-AGI future

    News & Updates

    Orchestrate generative AI workflows with Amazon Bedrock and AWS Step Functions

    Development

    Highlights

    Is there a good way to run selenium tests on a Linux machine against a WebKit browser?

    November 6, 2024

    A majority of our users are on mobile safari, but we run our automation in pipelines using a linux kernal. Is there a way a good option for running our tests in webkit-based browser to ensure it renders correctly on Safari (or as best we can)? I’ve seen webkitgtk, and I did find some driver documentation on it, but I don’t know anything about it AT ALL, other than it exists. Thanks!

    How to extract adb dumpsys response for validation?

    May 7, 2024

    Will using a VPN help protect you from malware or ransomware?

    April 1, 2025

    CVE-2025-4636 – Apache Airpointer Privilege Escalation Vulnerability

    May 30, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.