Dynamic horizontal scrolling

I need help implementing a site using React that scrolls horizontally.

I'm unsure how to implement certain aspects, so I am looking for some assistance.

Within a wrapper, I have multiple container Divs.

<div class="wrapper">
  <div class="section" id="section1"> <!-- Should occupy 100% of the screen -->
    <h2>Section Header</h2>
    <p>
      Some Text
    </p>
  </div>
  <div class="section" id="section2"> <!-- Should occupy 100% of the screen -->
    <h2>Section Header</h2>
    <p>
      Some Text
    </p>
  </div>
</div>

I want each .section to take up the entire width of the screen (not just the parent) and scroll horizontally.

.wrapper{
  background:#000;
  width:12000px; /* Must adapt based on content */
  position:absolute;
  top:0px;
  left:0px;
  bottom:0px;
}

My issue is that I do not want to specify a fixed width for the wrapper (as seen in my example with 12000px). I would like it to be flexible.

.section{
  width: 4000px; /* Should be equal to 100% of the client screen size */
  float: left;
  height: 100%;
}

What would be the most effective way to make the .wrapper dynamic, adjusting its width based on its content? And how can I ensure that the .sections classes occupy 100% of the screen width (and not just their parent)?

Additionally, any guidance on customizing mousewheel behavior would be greatly appreciated.

Thank you.

Answer №1

Give this a shot:

JavaScript:

      $(document).ready(function() {
            $('.scrolls').mousewheel(function(e, delta) {
                this.scrollLeft -= (delta * 40);
                e.preventDefault();
            });
        });

Cascading Style Sheets (CSS):

.wrapper {
  background: #EFEFEF;
  box-shadow: 1px 1px 10px #999;
  margin: auto;
  text-align: left;
  position: relative;
  border-radius: 5px;
  margin-bottom: 20px !important;
  width: 100%;
  padding-top: 5px;
}

.scrolls {
  overflow-x: scroll;
  overflow-y: hidden;
  height: 80px;
  white-space: nowrap
}

.scrolls img {
  display: inline-block;
  vertical-align: top;
  width: 100%;
}

HyperText Markup Language (HTML):

<div class="wrapper">
        <div class="scrolls">
            <img src="http://placehold.it/50x50" />
            <img src="http://placehold.it/50x50" />
            <img src="http://placehold.it/50x50" />
            ...
        </div>
    </div>

Check out the demo: http://jsfiddle.net/lotusgodkk/akqp2LoL/1/

Answer №2

.main{

}
.wrapper{
  height:300px;
width:400px;
overflow-x:auto;
overflow-y:hidden;
}
.section{
  width: 4000px;
  height: 100%;
}
<div class="main">
<div class="wrapper">
  <div class="section" id="section1">
    <h2>Section Header</h2>
    <p>
      Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
    </p>
  </div>
</div>
</div>

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

Customizing React components based on API data

const LinkList = () => { const [links, setLinks] = useState([]); const url = 'http://localhost:5000/xyz'; const hook = () => { console.log('effect'); axios .get(url) .then(respo ...

What could be causing my handle button to slide off the timeline towards the right?

I'm facing an issue with my volume bar component where the slider button is rendering outside of the timeline instead of on top of the progress bar. I need assistance in adjusting its position. // Here is the code for my volume bar component: import ...

Leveraging both Vuex and an Event Bus in your Vue application

For some time now, I've been pondering over this question that has been lingering in my mind. My current Vue application is quite complex, with a significant number of components that need to communicate effectively. To achieve this, I have implemente ...

What is the best way to create some distance between a div element and the bottom of the body?

Hello, I am attempting to center a div within my body. The div has a minimum height of 400px, but its size can expand based on the content it holds. When I add more content to the div, it grows accordingly, but it ends up touching the bottom of the div. I ...

Locate a row in an unselected data table using Jquery based on the value in a td

Is there an efficient way with jQuery to locate a td in a "legacy" datatable that contains my search value, and then navigate up the row tr? I am currently using $('#modalTable tbody').dataTable()[0].rows to retrieve all rows and then iterate th ...

Unable to close Bootstrap sidebar menu on mobile devices

I implemented a sidebar menu for mobile that opens when you click on the hamburger icon, with a dark overlay covering the body. The issue I encountered is that on mobile devices, the visibility of the menu does not change when clicked outside of it. It wor ...

Fixing Cross-Browser Issues with the OnScroll Function

window.onscroll = function() { if( window.XMLHttpRequest ) { var bodyId=document.getElementById('bodymain'); if (bodyId.scrollTop > 187) { //make some div's position fixed } else { //mak ...

Fetching the entire webpage

When attempting to load a specific webpage using an iframe, I encountered the following issue: <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title></ ...

Utilizing an Ajax call within "for" loops can result in skipping either odd or even iterations

Seeking assistance because we are facing a challenge that we cannot seem to overcome. Despite researching on platforms like StackOverflow and search engines, implementing a solution or solving the problem remains elusive. The goal is to develop a JavaScri ...

Displaying only the validation messages that are accurate according to the Vuetify rules

<v-text-field label='New Password' class="required" v-model='password' type='password' :rules="passwordRules" required> </v-text-field> passwordRules: [ value => !!value || 'Pl ...

Personalized HTML characteristics

Within the realm of AngularJS (and possibly jQuery UI), I've come across tags such as ui:some_random_name and ng:some_random_name. It seems that according to the HTML specification, non-standard attributes are not allowed. So how do these libraries m ...

Guide on retrieving the content type field value in Drupal and transferring it to a JavaScript file

In my custom Drupal theme, I have included a field for a SoundCloud URL with the machine name (field_soundcloud_url_). I am attempting to use a JavaScript file that will function based on the value of this variable. However, it seems to not be working as e ...

Establishing the httppostedfilebase variable when validation is unsuccessful in an ASP.Net MVC view

I'm currently facing an issue with handling validation errors in my application. I have implemented uploading and downloading images successfully, but when there are validation errors and the controller redirects back to the page, the HttpPostedFileBa ...

What are the steps for implementing Ajax in Django templates?

Looking to implement Ajax within Django templates? urls.py from django.conf.urls import patterns, url urlpatterns = patterns('', url(r'^home/$', 'views.index'),) views.py from django.template import RequestContext fro ...

Setting a value in Ionic 3 HTML template

Attempting to assign a value in an Ionic 3 template from the ts file while also adding css properties but encountered an issue. PROBLEM Error: Uncaught (in promise): Error: No value accessor for form control with name: 'image' Error: No va ...

Flask template fails to render following a redirect

I have embarked on creating a simple CARTO application using a combination of Vue JS and Flask. If you wish to explore the entire code, it can be accessed from this github repository. Here's how the application is designed to function: The user m ...

What is the method for including the sources directory within the require() scope in npm?

Upon examining my directory structure, the following layout is revealed: package.json /src a.js /test test_a.js The contents of package.json are as follows: { "name": "foo", "scripts": { "test": "mocha" }, "devDependencies": { "mocha ...

Hold off on running addThis

My website utilizes Google Maps along with my own JavaScript functions. Additionally, I am integrating the AddThis JavaScript for social sharing buttons. For optimal performance, I need both my custom JavaScript and Google's JavaScript to load and exe ...

Experiencing challenges with showcasing numerical values in the grid cells

My latest project involves creating an interactive sudoku solver. I've successfully created a grid made up of various elements to resemble an empty sudoku grid. However, my challenge lies in getting the numbers to display within the grid cells. Click ...

Is there a way to retrieve content in tinymce from a JSP file and send it to a servlet that then redirects to a different page

I need guidance on how to store the content from the tinymce editor and post it with a new page creation. What steps should I take? ...