What is the best way to address background-image overflow on a webpage?

I'm facing a challenge in removing the overflow from a background-image within a div. There are 4 divs with similar images that combine to form one background image (I adjust the position of each image so they align across the 4 divs). Essentially, I want to animate the "singular" image to the left and have another image replace it within the same animation (which is essentially a CSS transition). However, the issue arises when using overflow: hidden to hide the excess part of the image - moving it to the left reveals the rest of the hidden image.

Is there a method to clip or eliminate the overflow in order for the transition to appear as if one complete image is shifting to the left?

CSS:

.changeOver{
    background-repeat: no-repeat;
    background-position:130% !important;
    -webkit-transition: 2s;
    -moz-transition: 2s;
    -o-transition: 2s;
    transition: 2s;
}

The Script:


$('#change').click(function() {
   $('#fourth').addClass('changeOver');
    setTimeout(function(){ 
        $('#fourth').css('background-image', 'none'); 
    }, 5000);
    setTimeout(function(){ 
        $('#fourth').css('background-color', 'blue'); 
    }, 1);

    // Additional code for third, second, and first

});

For more details and a working example, check out this JSFiddle link. Just click on the button labeled 'yes'.

Answer №1

Update: After reviewing your code, I noticed that the issue lies in not moving the actual div elements themselves.

If you add {outline: 1 px solid red;} to the divs, you'll observe that they remain stationary while the background scrolls. Simply hiding the overflow won't solve the problem unless you physically move the divs.

One solution could be manipulating the image so that what appears beneath it is part of the same file. Essentially creating a seamless transition between images.

Imagine having |main image|next image| all connected seamlessly. This would give the illusion of the image being dragged into view.

For a more static reveal effect, you'd need to create four images with transparent sections where the overflow is expected.

This process can be easily done online using tools like pxlr.

Alternatively, consider animating the actual div elements instead of just

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

What is the process for activating namespacing on a VueX module that has been imported?

I am currently utilizing a helper file to import VueX modules: const requireModule = require.context('.', false, /\.store\.js$/) const modules = {} requireModule.keys().forEach(filename => { const moduleName = filename ...

Is it possible to launch a browser window using javascript?

I need to open a new Internet Explorer browser window and I am currently using the following code: window.open("http://jsc.simfatic-solutions.com", "mywindow"); However, I would like to know how can I open a new IE window with a fresh session? ...

Tips for creating a functional null option using the select ng-options feature

While there are a few questions and answers on this topic, I have yet to find a solution that works for my specific case. Imagine having an object like this: $scope.person = {name: 'Peter', category1: null, category2: null}; Another variable r ...

Warning: Using synchronous XMLHttpRequest on the main thread is no longer recommended as it can negatively impact the user's experience

I encountered an issue with my project while attempting an Ajax request [Warning] Using synchronous XMLHttpRequest on the main thread is now considered deprecated due to its negative impact on user experience. function retrieveReviews() { var reviewsD ...

Tips for Troubleshooting External Evaluation Scripts

For a specific example, take a look at the haystack.js script from How Big is Your Haystack? I've been searching for a solution and it seems that using the //# sourceURL=name.js comment is the way to go. However, I am struggling with the process of a ...

Is it possible to utilize the `.apply()` function on the emit method within EventEmitter?

Attempting to accomplish the following task... EventEmitter = require('events').EventEmitter events = new EventEmitter() events.emit.apply(null, ['eventname', 'arg1', 'arg2', 'arg3']) However, it is ...

Processing PHP response while waiting for jQuery AJAX call

I utilized an ajax function to transmit data. Within the PHP process, I executed phpmailer to send emails by using smtp gmail. The procedure proceeded smoothly, however, there are instances where I require informing the user to wait for the ongoing process ...

Newbie struggling with executing JavaScript in Visual Studio Code

Hey there! I'm new to coding and have been struggling for the past couple of hours trying to get a simple JavaScript code to run on VSC. Can anyone lend a hand in helping me set up my sandbox correctly? Here's a snapshot for reference: https://i ...

Implement the AngularJS orderby filter based on a checkbox selection

Is it possible to use the angularJS orderby filter with a checkbox for ordering columns? I currently have this working as expected: <tr ng-repeat="player in players | orderBy:'id':true | rangeFilter:min:max"> <td>{{player.id}}</ ...

How can I append a hash to a URL using JavaScript without causing the page to scroll?

Is it possible to add a hash to the URL without scrolling the page using JavaScript? I navigate to the page I scroll down I click on a link that adds a hash (for example: http://www.example.com/#test) The page should not scroll back to the top. What is ...

CSS based on conditions for 2 specific divs

Hello, I am working on an HTML page where I need to apply CSS only if certain conditions are met. The div with the id "flipbook-page3-front" will always be present on this HTML page. Sometimes, another div with the id "pagesFlipbook" may also appear on t ...

Tips for resetting a bootstrap modal post form submission using jQuery

After completing an ajax request in my application, I am looking to reset the bootstrap modal. How can I ensure that the modal is reloaded fresh after it has been submitted previously? I have attempted using removeData() and .modal('dispose') me ...

AngularJS is experiencing issues with the sorting filter 'orderBy'

I am experiencing an issue with sorting a table list that has three columns. I have implemented the ability to sort all columns in ascending and descending order. However, when I click on the -Tag to initiate the sorting process, I encounter the following ...

Having trouble with the `click()` function not working on a button while using Selenium in

Currently, I am running a selenium test on a remote server in headless mode using the chrome driver. However, when trying to click on a button with the following step, the button does not get clicked. Below is the test step attempting to click the element ...

Unable to access the ajaxComplete function while using .ajaxComplete with a datepicker change function

I'm facing an issue with my datepicker where I need to trigger a query as soon as a date is selected. I've been trying to implement the functionality using .ajaxComplete but seem to be unable to access it properly. Any suggestions on how to resol ...

Checking variable length time with JavaScript Regular Expression

My specific requirement is to validate a string ranging from 1 to 4 characters in length (where H stands for hour and M represents minutes): If the string has 1 character, it should be in the format of H (a digit between 0-9). A 2-character string should ...

Top div click causes bottom div to slide

I'm currently working on a project that involves using CSS and jQuery, but I've encountered an issue that I haven't been able to solve. Here is the demo link: . When the second div is clicked, why does the third div slide? How can this prob ...

Ensure that grid rows occupy the least amount of space possible

I'm relatively new to grid layout and I've encountered a challenge that has me stuck. Here's what I have so far: codepen And this is the relevant part of the grid: grid-template: 'img date' 'img head' 'img s ...

Retrieve the maximum number of slots from a JSON file and implement them into the

I've encountered an issue with my upload form. After uploading and previewing an image, I want to add it to a list as long as the list still has available slots. Here's an example: If the maximum number of slots is set to 5, then you can add up ...

The addition of the URL # fragment feature to Safari's browser caching system

Currently, I am focused on improving the speed of our website. To achieve this, the client is utilizing ajax to preload the expected next page of the application: $.ajax({url: '/some/real/path', ...}); Upon receiving a response from the server ...