Code

Scroll overflow move on click

Utilize buttons to move between cards within an overflow: scroll wrapper to a specified card via each button in Webflow. This uses a simple JS code to allow seamless transitions between various cards of your choosing using an overflowed wrapper.

Scroll overflow move on click preview

Utilize buttons to move between cards within an overflow: scroll wrapper to a specified card via each button in Webflow. This uses a simple JS code to allow seamless transitions between various cards of your choosing using an overflowed wrapper.

How to add it

  1. Add teh Javascript code snippet to your pages closing body section or as an embed
  2. Utilize the button element IDs and signify your button IDs within Webflow

The code

Javascript
                      <script>
$(function() {
        $('#btn1').click(function() {
            $("#overflow-wrapper").scrollLeft(0); //scroll left to start since first card
        });

        $('#btn2').click(function() {
            let cardWidth = $(".card").width() + 20; //variable for width of card, plus 20px margin-right
            $("#overflow-wrapper").scrollLeft(cardWidth); //scroll left the amount of variable
        });

        $('#btn3').click(function() {
            let cardWidth = ($(".card").width() + 20) * 2; //same as previous, plus x2 since moving two cards
            $("#overflow-wrapper").scrollLeft(cardWidth); //scroll left the amount of variable
        });
    });
</script>

                    

Browse similar code snippets

Categories

Language

More from Corey Moen

Profile →

Related Webflow questions

All answers →

Similar code snippets

All code snippets →