Horizontal image scrolling problem across different browsers

Check out my Fiddle.

I'm having trouble with scrolling on different browsers. In Chrome, the scroll behaves as expected and stops when the content ends. However, in Firefox, it keeps scrolling even after reaching the end despite setting a fixed width for the div.

The issue lies in not knowing how many images will be loaded from the database, making it impossible to use a fixed width for scrolling. How can I resolve this?

I currently use mouse drag for scrolling.

CSS Code:

#timeline {
    height: 375px;
    margin-top: 10px;
    padding: 20px;
    overflow: auto;   
}

.tl-events {
    width: 11800px;
    list-style: none;
    padding: 0;
    margin: 0;
}

.tl-events li {
    float: left;
    width: 300px;
    margin-right: 10px;
}

.tl-events ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

HTML Code:

<div id="timeline">
        <ul class="tl-events">
            // HTML code here...
</ul>
    </div>

JS Code:

$(document).ready(function () {        
        // JS code here...
    });

    $(window).mouseout(function (event) {
        // More JS code here...
    });

What could be causing this issue? Any insights would be greatly appreciated.

Answer №1

To see the changes, include

display: inline-flex; width:auto;
in the .tl-events class.

Answer №2

To properly set the width of .tl-events, you should dynamically calculate the width based on the element that wraps the li options instead of using a static width like .tl-events { width: 11800px;. Here is how you can resolve this:

var welcome = $('.welcome'), cont=0;

$(welcome).each(function(index) {
    cont++;
});

var welcome_w = $('.welcome').width * cont;
$('#timeline').css('width', welcome_w);

In order to achieve this, within your $(document).ready function, utilize the 'welcome' element to obtain its width and then multiply it by the number of welcome elements. Additionally, make sure to remove the width property from the css of your .tl-events class for best results.

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

Effortlessly accessing API with AJAX login using jQuery

I'm trying to implement a login form using AJAX and jQuery for an API. When I run the following command in the terminal: $ curl -d '[email protected]&password=123123' The response includes a hash containing an API token and Auth I ...

"Encountered a Chrome RangeError: The call stack size limit was exceeded while utilizing jQuery's $

As part of my job, I am currently evaluating a web application that involves fetching a substantial amount of data from the server. The data is received as a JSON object using the $.ajax function. It contains numerous sub-objects which I convert into array ...

The setInterval function does not function properly in IE8 when set to 0

I have a function called changeColor that updates the styling of certain elements in my HTML. In order to apply this function, I am using a timer like so: var timer = setInterval(changeColor,0); The issue I am encountering is that setting the time interv ...

Using AJAX to send data from knockout observables to the server in JSON format

I'm currently facing an issue where I am trying to send form fields that are linked to specific observables to my server as a JSON object, but I keep receiving an empty JSON string on the server side. I want to avoid sending the entire view model just ...

Break down the POST array into separate variables

I am currently working on coding a form using jQuery .post. The processing file contains the code: print_r($_POST); This code generates the dynamic output below: Array ( [data] => capacity=50-1000+people&bookingdate=17%2F04%2F2012&grade=1+sta ...

Text in React Native exceeding one line is causing it to extend beyond the screen boundaries

I am having trouble displaying the last messages in my simple contact list as the text is getting cut off the screen. Below is the code I am using: (the readableTimestamp should be positioned behind the text.) View style={{ fontSize: 16, backgro ...

Generate numerous div elements by utilizing ng-repeat

I am trying to generate 'n' red blocks with text (where n represents the number of elements in an array), but unfortunately, I am seeing a blank page. <html> <body> <script src="https://ajax.googleapis.com/ajax/libs/angu ...

Using React Refs to Trigger the video.play() Method - A Step-by-Step Guide

Is there a way to use a ref in order to trigger video.play()? Currently encountering an error: preview.bundle.js:261916 Uncaught TypeError: _this2.videoRef.play is not a function Take a look at my component: import React from 'react'; import s ...

The output I receive when making a jQuery POST request is a response generated by my index controller, although I am not specifically directing it there as I have

Currently, I am working with the latest version of codeigniter. After sending a post request, all I am receiving back is my view. This situation has left me puzzled. Listed below are my routes: $route['default_controller'] = "veebn"; $route[&a ...

Finding all anchor tags in raw HTML using htmlagilitypack

My HTML document contains the following code snippet: string htmlData = "<!DOCTYPE html><html><Head></Head><body>&lt;div&gt;&lt;a target=\"_blank\" href=\"http://blender.palmbeachschools.org/GetFile ...

Having trouble with the JQuery class selector?

Having a bit of trouble trying to select an element based on its class using $(".class"), and I can't seem to figure out why it's not working. So, the deal is - I have this image element that should appear when a function gets triggered: $("#co ...

Utilizing absolute positioning with a rotated div element

The situation I am facing involves a parent div and child div. The child div is positioned absolutely with respect to the parent div and has been rotated by an angle of 90 degrees. Due to the fact that the origin is located at the center of the child div ( ...

How can one use Selenium to verify the existence of an element on a webpage?

Currently, I am developing a program in Selenium with Python and facing an issue. During the test execution, there is a possibility that a button may or may not appear on the webpage based on an unknown parameter. The relevant HTML tag for this button is ...

Click outside of this popup to dismiss it

I have been struggling to figure out how to make this popup close when clicking outside of it. Currently, it only closes when clicked directly on it. Your assistance in this matter is greatly appreciated. Here is the HTML code: <h2>Popup</h2> ...

Avoiding metacharacters and utilizing them as a string variable for selection

For example, I have a variable called myid, and its value is "abc xyz". Then, I use a function to escape metacharacters and assign the result to another variable like this: var x = "#"+escapechars(myid);. The evaluated value of x is #abc\\xyz. ...

The issue with updating the menu class in Internet Explorer 8 is not being resolved

Here is a code snippet using JavaScript: var x = jQuery(window).innerHeight(); jQuery(document).scroll(function() { if (jQuery(this).scrollTop() >= x) { jQuery('#nav').removeClass('nav').addClass('topfix_nav'); ...

Adjust the opacity of certain elements to be semi-transparent, with the exception of the one currently

I'm attempting to implement the :not selector in conjunction with :hover to create a visual effect where elements that are not being hovered over become semitransparent. My goal is as follows: 1) All elements start at 100% opacity 2) When an elemen ...

Is there a way to automatically mute the sound on a parallax website homepage video when I navigate back to the homepage from another page?

Is there a way to automatically mute the sound of the homepage video on a parallax website when navigating back to it from a separate page? If I click on the enter button and navigate to the "Our DNA" page, then click on the events link in the menu from t ...

Discovering the current active link and anchor tag details using jQuery in an unordered list

I am currently utilizing jQuery to work with 4 anchor tags inside an unordered list, and I would like to be able to determine the "current active link" when a user performs a search. This way, I can execute my query based on the selected anchor tag. How ca ...

Utilize Bootstrap to position the button right next to the input field

I am having trouble aligning the button on the right next to the email textbox. Unfortunately, my attempts have not been successful. Fiddler: https://jsfiddle.net/Vimalan/mt30tfpv/4/ <div class="col-xs-3"> <div class="fo ...