How can I improve the smoothness of my CSS transition when resizing background images?

I'm currently working on creating an intro movie for a game and I thought it would be interesting to use CSS animations. However, I've noticed that some parts of the animation appear bumpy and inconsistent. It seems that depending on the transition-timing-function used, certain parts of the animation run smoothly while others become jerky. I'm perplexed as to why some portions move seamlessly while others suddenly stutter within the same transition.

Could it be that I'm making errors in my approach? Are there more effective methods to accomplish this?

Click here for code snippet

HTML

  var screen1 = $('#screen1');
  var screen2 = $('#screen2');

JavaScript

  screen1.css({
      'background': 'url(http://uniquenaturewallpapers.com/wp-content/uploads/2013/01/3d-underwater-Wallpaper.jpg)',
          'background-position': 'left center',
          'background-size': '100%',
          '-webkit-filter': 'none'
  });
  screen2.css({
      'opacity': '0'
  });

  setTimeout(function () {
      screen2.css({
          'opacity': '1'
      });
  }, 20000);


<div id="screen1"></div>
<div id="screen2"></div>

CSS:

#screen1, #screen2 {
    background: black;
    background-size: 150%;
    background-position: 100% 50%;
    -webkit-filter: grayscale(100%);
    filter: grayscale(100%);
    z-index: 10;
    position: absolute;
    width: 100%;
    height: 100%;
    transition: 30s ease-in, -webkit-filter 20s ease-in 8s;
}

Answer №1

Although this method may be considered outdated, I struggled with it until I discovered an effective way to incorporate the scale feature.

Take a look at the demo on the fiddle:

http://jsfiddle.net/YEvCU/6/

I utilized transform: scale(3) and then initiated an animation transitioning to transform: scale(1).

Here is the HTML setup:

<div id="screen1"></div>
<div id="screen2"></div>

For the JavaScript part:

var screen1 = $('#screen1');
var screen2 = $('#screen2');

screen1.css({
    'background': 'url(http://uniquenaturewallpapers.com/wp-content/uploads/2013/01/3d-underwater-Wallpaper.jpg)',
    'background-position': 'left center',
    'background-size': '100%',
    '-webkit-transform': 'scale(1)',
    'transform': 'scale(1)',
    '-webkit-filter': 'none'
});
screen2.css({
    'opacity': '0'
});

setTimeout(function () {
    screen2.css({
        'opacity': '1'
    });
}, 20000);

Here are the CSS styles being applied:

#screen1, #screen2 {
    background: black;
    background-size: 100%;
    background-position: 100% 50%;
    -webkit-filter: grayscale(100%);
    filter: grayscale(100%);
    -webkit-transform: scale(2);
    transform: scale(2);
    z-index: 10;
    position: absolute;
    width: 100%;
    height: 100%;
    transition: 30s ease-in, -webkit-filter 20s ease-in 8s;
}

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

When the screen is minimized, my website doesn't align to the center as expected

When the screen is maximized everything looks great, but when I minimize it, the content doesn't center. I tried using margin: auto; in the "main-div" class, but then everything shifted to the top left corner. So, I added a "wrapper-div" to contain th ...

Is there a way to customize the hover effect on this navigation link in Bootstrap that includes a span and an icon from Bootstrap?

<li class="nav-item mt-3"> <a href="#" class="nav-link px-2 d-flex justify-content-start align-items-center"> <i class="nav-icon bi bi-calculator-fill fs-4"></i> ...

Stop manipulating links with jquery mobile to maintain original behavior

I have a situation where I am listing WordPress posts, and when I click on a title, jQuery is loading the single post page for me via ajax. However, I don't want this behavior - I just want the link to act normally. I have tried using the following co ...

Creative Vue.js and Tailwind CSS card layout featuring an image extending beyond the boundaries of the card

I'm attempting to design a card where an image pops out of the card. I've tried using z-index, but it doesn't seem to be working as expected. Here is the code I have: <div class="flex flex-col"> <div class=&quo ...

Reliable drop-down box is not functioning properly

I am new to AJAX and I came across a solution for my issue on this page, but I am having trouble getting it to work. I want the input #precio to change when I select an option in the select #producto. This is the code I have: <form action="actualizar ...

Creating an undo feature for a dynamically generated checklist of checkboxes

I am using a combination of javascript/jquery and html to dynamically populate the page with checkboxes. When you click "add", a new checkbox is created. I am now looking for a way to add an undo button that would delete the last checkbox created. Here is ...

Changing the color of tabs using inline styles in material ui does not seem to work

I am brand new to using material ui and have been attempting to alter the colors of the selected tab. Currently, the color is a dark blue shade and I am aiming to change it to red. I tried applying inline styles, but unfortunately, there was no change. C ...

The width of table columns is altered upon the second rendering in JQuery DataTables

Is there a way to prevent JQuery DataTables cells from extending width after adding hyperlink to cell? I am facing an issue where I have two tables on the same page. The first table column has a link which populates the second table. It works fine when th ...

Retrieving the selected date from JqueryUI Datepicker after form submission

I am currently using an inline datepicker that fills in an input textbox. $("#left-calendar").datepicker({ altField: "#left-date-text" }); The left-date-text is located within a form, and upon submission with a submit button, it sends the data to a p ...

The dropdown menu vanishes from sight as soon as the cursor moves away from a link

Recently, I encountered an issue while trying to create a dropdown menu using Jquery. The problem arose when attempting to select the second link, as the entire menu would disappear. Additionally, is there a way to ensure that only one dropdown menu is vis ...

When adding files through drag and drop, the FormData is including a blank file field in the sent

I am currently working on a photo upload page that has drag and drop functionality enabled. Below is the form code: <form id="Upload" method="post" action="sessionapi/UserPicture/Upload" enctype="multipart/form-data"> <input class="box__file ...

A comprehensive guide on associating a JavaScript function with an element attribute

I am looking for a way to assign a JavaScript function to an HTML attribute. For example: <li data-ng-repeat="job in jobList" class= dynamicClass(str) data-filter = "dynamicFilter(str)"> The reason I want to do this is because the class name and ...

What is the best way to ensure that my <h1> header stays above my <h2> header at all times?

As a novice in web design, I recently took on the challenge of creating my own website. I am a graphic designer and came up with a mock-up of how I envision the site to look. While I managed to complete most parts of it, there's one specific area wher ...

Exploring JQuery techniques for iterating through numerous JSON files to create dynamic quizzes

Hi everyone, I could really use some assistance right now. I am working on developing a front-end system for a quiz, but I have encountered a challenge with the back-end. The back-end provides 3 JSON files to work with. JSON1 contains category and title in ...

Adding data from a database into an object in PHP for temporary use during the loading process can be achieved by following

I'm a beginner in PHP and I have some code that retrieves category type data from a database. I want to temporarily store this data in a PHP object while the page is loading. Initially, I need to load all predefined data and then use it when a certain ...

The functionality of a basic each/while loop in jQuery using CoffeeScript is not producing the desired results

I've been experimenting with different methods to tackle this issue. Essentially, I need to update the content of multiple dropdowns in the same way. I wanted to use an each or a while loop to keep the code DRY, but my experience in coffeeScript is li ...

The scrolling action triggered by el.scrollIntoViewIfNeeded() goes way past the top boundary

el.scrollIntoViewIfNeeded() function is used to scroll to element el if it's not within the visible browser area. Although it generally works well, I have encountered some issues when trying to use it with a fixed header. I have provided an example s ...

Grails is experiencing a surge of duplicate events being triggered simultaneously

In my _test.gsp layout, I have a 'click event' that is triggered when the layout is rendered as shown below. <div id="testid"> <g:render template="test"/> </div> When I click on the event in the _test.gsp layout, it trigge ...

Toggle the display of slide numbers in RMarkdown xaringan / reveal.js presentations

In preparation for a workshop, I am creating HTML slides using the xaringan package in R, which is based on remark.js. These slides are made with RMarkdown, and while this approach has been effective, I have encountered a need to disable slide numbers on s ...

Dealing with AngularJS memory leaks caused by jQuery

How can I showcase a custom HTML on an AngularJS page using the given service? app.service('automaticFunctions', function ($timeout) { this.init = function initAutomaticFunctions(scope, $elem, attrs) { switch (scope.content.type) { ...