Enhancing user experience with scroll snapping within nested components/elements

https://i.sstatic.net/PzNmP.gif

Looking at the gif, you can see a large scrollable container with various main blocks ('Attack', 'Release', etc.) housed within it. Each main block contains one or multiple columns (such as 'Attack time' under Attack, and 'Threshold', 'Density', etc. under Levels).

The basic HTML structure is outlined below:

<div class="big-scrollable">
  <div class="main-block">
    <h4>Attack</h4>
    <div class="column-container">
      <div class="column">
        <!-- Attack time -->
        <... content ...>
      </div>
      <div class="column shown-when-expanded">
        <!-- Some other column -->
      </div>
    </div>
  </div>
  <div class="main-block>
    <h4>Release</h4>
    <div class="column-container">
      <div class="column">
        <!-- Release time -->
        ...
      </div>
      ...
    </div>
  </div>
  ...
</div>

I am aiming for the big scrollable container to snap to each small column like 'Attack time', 'Release time', 'Threshold', 'Density', etc.

I attempted styling the elements using the following CSS:

.big-scrollable
{
  overflow-x: auto;
  scroll-behavior: smooth;
  scroll-snap-type: x proximity;
}

.column
{
  scroll-snap-align: start;
}

However, this approach did not work as expected. Is there a way to achieve this purely through CSS, or will I need to resort to JavaScript?

EDIT:

The Codepen example shared by Jonas Weinhardt does seem to work and uses similar CSS settings.

I have included more of the code I am working with in the Pastebin snippets below. (Please note that I have altered the class names for better clarity in this question)

Important HTML: https://pastebin.com/DjvJt8v1

Important CSS: https://pastebin.com/tmLQQhbU

Answer №1

Solution for this particular scenario

After experimenting with the actual css classes and html structure (links provided in the question), I was able to identify the issue. The classes .big-scrollable and .column suggested by T. J. Evers are correct and do not need to be altered for it to work. The main problem was that the .column-container class also had an overflow property set, which disrupted the intended functionality.

In essence, none of the child elements within your primary scroll container (in this case: .big-scrollable) or the container you wish to snap to (in this case: .column) should have an overflow property assigned for this to function as intended!

(except for overflow: unset, naturally)

Here is a Codepen link showcasing the working html structure from this query: https://codepen.io/jonas_weinhardt/pen/mdmqypr

Initial Answer (Can disregard this)

I made these adjustments and it appears to be effective:

.big-scrollable{
  overflow-x: scroll;
  scroll-snap-type: x mandatory;
}

.column{
  scroll-snap-align: start;
} 

This also functions with scroll-snap-type: x proximity; if you prefer this behavior.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

``Is it feasible to extract a PDF file using a PDF viewer in selenium using C# programming language

Facing an issue with downloading PDF files using JavaScriptExecutor: I am trying to automate the process of downloading a PDF file in a new window using JavaScriptExecutor. The online PDF viewer window has a toolbar section with options like print and d ...

Tips for setting background colors as a prop for Material UI cards in React JS

Currently utilizing the Material UI next framework to construct a wrapper for the card component. This customized wrapper allows for personalization of the component. I have successfully extended the component so that the title and image within the card ca ...

Error message: JavaScript is unable to save data to an array retrieved from Ajax, resulting in

I am facing an issue with retrieving continuous data from the database using AJAX and storing it in a JavaScript variable. Despite my efforts, I am unable to populate an array with the retrieved values as they always end up being undefined. Below are the s ...

Issue with array merging/inserting feature not functioning as expected

Here are two arrays that I have: First Array: "workingHours": [ { "opening": "09:30", "closing": "13:30", "dayName": "sunday" }, { ...

Is it possible to preload numerous extensive datasets in the background using ajax?

I'm currently in the process of developing a web application that operates solely on one page and revolves around presenting various table data in grids. There are approximately 30 different tables stored in the database, with any of them being access ...

Moving the legend around in vue-chartJS

As someone just starting out with Vue-ChartJs, I've become quite intrigued by this: https://i.sstatic.net/j1S0z.png I'm wondering how to move the legend to the bottom of the graph. Can anyone help me with that? ...

Creating a stripped box shadow with just HTML and CSS - a simple guide

Hey there! I'm trying to create a navbar button with a cool stripped box shadow effect when hovered, similar to what you see in this image link. I attempted to achieve this using CSS box-shadow and linear gradient, but unfortunately it didn't qui ...

Issues with npm installation

Having trouble installing 'react-navigation' in my expo (react native) project using the command 'npm install --only=dev react-navigation'. I keep receiving warnings and am unsure how to proceed. See image link for details: enter image ...

Setting up a static directory in Node Express to serve index.html along with additional tsv files

I'm encountering an issue with setting up a static folder for a project using the d3 node package. My approach involves using express to host a server.js file, which is structured as follows: var express = require("express"); var app = express(); var ...

Exploring the depths of cURL and PHP beyond the basics

After realizing that my previous question was not quite right, I am back with a more accurate one. This time, I am working with cURL in PHP and trying to access a website. However, every time I change the site, the browser sends a value x to the server. If ...

What is the method for getting js_xlsx to include all empty headers while saving the file?

In the midst of developing a Meteor App, I've incorporated the Node.js package known as "js_xlsx" from "SheetJS", produced by "SheetJSDev". This tool enables me to convert an Excel sheet uploaded into JSON on the backend. The intention is to store thi ...

The AJAX request for JSON data is functioning correctly in Firefox, but is experiencing compatibility issues with other web browsers

I recently completed a PHP page that generates a valid JSON document. The jQuery code used to fetch and display the data is quite straightforward: $.ajax({ url: "http://localhost:8888/rkm/json-jc", dataType: "json", success: function(data) { ...

Ways to troubleshoot and resolve the jQuery error with the message "TypeError: 'click' called"

I am currently developing a project for managing Minecraft servers, focusing on a configuration panel. I have set up a form that users need to fill out in order to configure the settings and send the values using Ajax. However, I encountered an error: Type ...

Issue with Vue 3: Composition API does not support Array of refs

Check out the code snippet below. <template> <div v-for="item in arr" :key="item">{{ item }}</div> </template> <script> import { ref } from "vue"; export default { name: "TestArr", ...

Is it necessary to have NodeJs in order to host a React app on a server?

I've been working on a .NET Core 2.2 project with React integration, As I'm nearing completion of the project, I have a query that has been on my mind. Do I need Node.js installed on the server for React to function properly? Thank you. ...

What is the right way to send a success response from Express JS to Backbone when logging out a user?

I'm currently learning how to work with Express JS and Backbone. On the server side using Express.js, I have this code snippet for logging out a user: app.get('/logout', function(req, res) { req.logout(); res.send('How can I ...

Enhancing selector choices with Vuejs2 updates

Having trouble updating the options array within a select element in a VueJS component. I have multiple rows, each containing a select element. All select elements should use the same set of options. When an option is selected in one select element, it sh ...

Is this JavaScript code accurately matching the height of all three elements?

What I aim to achieve https://i.sstatic.net/aNCWV.png I attempted to create a condition-like statement: [ Comparing the heights of the 3 elements ] → When all are smaller than the height of content: Stretches to the full height of content. (jus ...

Setting a React component state as the default value for a function parameter

During a recent code review, I came across an interesting function definition in one of my colleague's implementations. The function was implemented inside a react component with default parameter values set in case no argument is provided during the ...

Tips for converting Javascript require to Typescript import using the const keyword

Recently, I've been attempting to import faktory_worker_node from github.com/jbielick/faktory_worker. The README provides the following instructions: const faktory = require('faktory-worker'); faktory.register('ResizeImage', asyn ...