Problem: Implementing a horizontal scrolling feature using Skrollr

I'm interested in creating a horizontal animation controlled by skrollr. As I scroll down, I want the elements on my page to move from left to right within my container.

When all elements have the same width, setting the scrolling data from 100% to 0% works perfectly.

However, what if my images have different widths? Additionally, I would like to maintain the opacity animation for a fade-in, fade-out effect.

Below is the HTML code:

<div id="container">
    <div class="bg" style="background-color:red" 
        data-0="transform:translate3d(0%,0%,0); opacity:1"  
        data-5000="transform:translate3d(-100%,0%,0); opacity:0">
    </div>

    <div class="bg" style="background-color:green;" 
        data-0="transform:translate3d(100%,0%,0); opacity:0"    
        data-5000="transform:translate3d(0%,0%,0);opacity:1"
        data-10000="transform:translate3d(-100%,0%,0);opacity:0">
    </div>

    <div class="bg" style="background-color:orange" 
        data-5000="transform:translate3d(100%,0%,0); opacity:0"     
        data-10000="transform:translate3d(0%,0%,0); opacity:1">
    </div>
</div>

And here's the CSS:

#container {
    background-color:black;
    width:500px;
    height:300px;
    overflow:hidden;
}
div {
    position:fixed;
}
.bg {
    width:500px; 
    height:300px; 
}

Check out the Demo in Fiddle

Answer №1

To ensure your images fill the entire width, set the widths to 100% and enclose them within a container:

#wrapper {
    background-color:black;
    width:100%;   
    height:300px;
    overflow:hidden;
}
img {
   position:fixed;
}
.bg-img {
    width:100%; 
    height:300px; 
}

Check out the live demo on Fiddle

Answer №2

It's not just about the width - think about how the height might affect the image display as well. Consider setting all dimensions to 100% with overflow: hidden, or utilize jQuery to dynamically adjust the image size to fit the container perfectly.

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 possible to craft poetic lines with indents in HTML using blockquotes, pre, or dd tags?

I am struggling to format a few lines of text with indentations using HTML. Here is an example I found: HERE Below is my attempt: <p><code>"Knowing is not enough. We</code></p> <p><blockquote><code>must apply. Wi ...

Generating an interactive Datepicker using Jquery

How can I design a dynamic date picker similar to the image provided below? https://i.sstatic.net/euoNI.png I have attempted to create one, but I am looking for a more interactive date picker. Is there a way to achieve the design shown in the image? The ...

Using jQuery in an ASP.NET user control seems to be causing some trouble

Has anyone had issues with the jQuery colorbox plugin not working in an asp.net user control, even though it works fine on an asp.net page? What could be causing this inconsistency? <html lang="en"> <head> <meta charset="utf-8" /> ...

Is there a way to speed up the loading time of React in the browser?

My experience with using React in the browser has been positive, but I'm facing a speed issue. The initial loading time is quite lengthy as it compiles. I am looking for a way to use React/JSX directly in the browser and have it compile instantly wit ...

Why am I unable to locate my personalized module?

I've encountered an issue with my npm module not being found in my sample script after publishing it. Here is the link to my module: https://www.npmjs.com/package/kong-hmac https://github.com/y-zono/kong-hmac-js Here's what I have tried: $ m ...

What is the most efficient approach for handling numerous transactions individually through AJAX calls?

Just a heads up: there's quite a bit of pseudo code coming up, but it's necessary to illustrate my issue. My solution involves more complex management of ajax icons and statuses, but I've simplified it for clarity. Essentially, I'm fac ...

Storing Data in an Array Using MongoDB's $push Method Depending on a Variable's Value

I'm attempting to add an item to my MongoDB record in Node (using MongoJS) by using the $push method. Here is an example of how it's done: exports.saveToUser = function (req, res) { console.log("IN"); var user = req.params.user; var ...

Overflow scrollbars do not appear on flex divs

I am struggling with implementing a simple flex container that contains standard divs. The issue I am facing is that the overflow does not display a vertical scroller as desired. In order to achieve this, I have included the following CSS code snippet: #c ...

Tips on customizing default Polymer CSS

Currently, the core-toolbar features an indent class that shifts the title to the right by 60px. However, material design guidelines suggest that the margin should actually be 80px (oddly enough, the number 60 is not mentioned in the documentation). I cou ...

Navigating Users to View Their Recently Posted Topic After Clicking Submit in CodeIgniter

Users are able to write articles using a form on my website. Once they submit the form, I want the system to redirect them to view their new post (typically displaying a success message). Controller if ($this->form_validation->run() == TRUE) { ...

What could be causing the incorrect execution of this MySQL update within PHP?

Recently, I've been trying to update a specific row in my database table. To locate the exact row for updating, I use an email address entered into a form as a search key before inputting the remaining data needed for the update process. However, ther ...

Having trouble getting Javascript to reveal hidden elements based on their class

I am having some trouble making specific fields in a form appear based on the selection made from a dropdown menu. Below is a simplified snippet of my code, which should change the display from 'none' to 'block'. Can you help me figure ...

Failure to trigger an event in Vue.js

I've implemented an overlay feature for my modal that should toggle the modal when clicked. Here's the code snippet I have in my mounted() method: const overlay = document.querySelector(".modal-overlay"); overlay.addEventListener("click", this ...

What could be causing my carousel slider images to not adapt to different screen sizes?

I recently added a carousel slider to my website, and while it looks great on larger screens like desktops and laptops, I noticed that the images are not scaling properly when viewed on smaller screen widths. This has resulted in non-responsiveness which i ...

When setting the margin to auto, it perfectly centers elements on servers and IE, but on Chrome off the server, it appears to be aligned to the

There seems to be an issue with the display of my page in Chrome - it starts at the middle and ends on the right side. However, when I view it on my server or try it on Internet Explorer 11, it appears centered. Why is that? This problem only arose after ...

Refreshing the page after executing a MySQL UPDATE statement

There seems to be a problem with the page refreshing faster than the query execution. I have an UPDATE query to update my database with values in my fields, triggered by pushing a button. However, upon clicking the button (which refreshes the website), th ...

What steps should I take to ensure that my website can recall the most recent interaction conducted by the user?

Our website features a search form that allows users to look for items on the page. In addition, there is a separate form with checkboxes that enables users to narrow down their searches in hopes of reducing the number of results returned. For example, i ...

The action does not execute when the form is submitted

I’m currently working on a simple registration form, but I’ve encountered an issue with my code. Despite troubleshooting, I can’t seem to identify any errors in my code. Upon submission of the form, the page fails to redirect to register.php. Below ...

Incorporating a divider into a Material-UI MenuItem causes an additional border

I needed a way to separate the MUI MenuItem using a divider, but it resulted in an extra border around the item where the divider was placed. The highlighted section in the image shows the item that has the divider= true setting and the extra border. Is th ...

Flowplayer playlist stops after playing the first clip

I am having issues with my flowplayer configuration, as it is not behaving as I expected. After the first video ends, I want the second and subsequent videos to play automatically. Can anyone provide some guidance on how to achieve this? $f("player", "/fl ...