Mastering smooth zoom and scroll effects in JavaScript without any flickering

My web application has a zoom feature that scales some absolutely positioned DIVs while keeping the scroll position intact. However, during the animated zooming, there is a noticeable flickering effect where the boxes seem to jump up and down slightly. I am looking for a solution to make this animation smoother.

If you want to see the issue in action, you can visit this link: http://codepen.io/excelkobayashi/pen/EKVmrK. The flickering becomes more pronounced as you scroll further down on the page. In my actual application, the problem is even more evident due to the complex nature of the DOM.

Pay attention to the top edge and the text:

https://i.sstatic.net/85PTP.gif

Here is the relevant code snippet responsible for handling scrolling:

    var oldZoom = zoom;
    zoom += step;

    render();

    scrollPos = ((zoom / oldZoom) * scrollPos) || 0;
    $("#container").scrollTop(scrollPos);

Key points to note:

  • This entire block is executed within a requestAnimationFrame loop to animate the change in zoom level
  • 'Step' represents a fraction of difference between the current zoom level and the target zoom level, creating an ease-out effect
  • The 'render' function handles resizing and moving the DIVs inside the scrollable area

Answer №1

The flickering effect occurs when you adjust the scrollTop property of the container in increments. To achieve a smooth transition for changing the scrollTop value, consider using jQuery's .animate() method (http://api.jquery.com/animate/).

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

A guide on showcasing items on an html webpage through the use of javascript

Currently, I have a series of hardcoded HTML elements in my code snippet. <!-- Reciever Message--> <div class="media w-50 ml-auto mb-3"> <div class="media-body"> ...

Burger on a website designed for desktop users

In my project, I am looking to only display a hamburger icon with a list of items on mobile view. I do not want any menu items in the navbar on desktop and tablet views. Is there a way to achieve this using Bootstrap or another method? Any suggestions for ...

Load gallery thumbnails dynamically using JavaScript or jQuery

Currently, I have implemented TN3 gallery in a WordPress website (not as a plugin, but as a jQuery library). While the large images in the gallery load dynamically and do not affect the page load, the thumbnails are all loaded at once, even if they are no ...

Unable to get the deletion functionality to work for Dropzone.js and PHP script

I am currently using dropzone to handle file uploads. My goal is to delete the files on the server when the user clicks on the removeLink. I have implemented an Ajax function that calls a .php site for this purpose. However, I am facing an issue where I am ...

Tips for expanding button width in 'react-native-swipeout' to enable swipe action on ListView row (React Native)

Currently, I am exploring how to implement the component found here: https://github.com/dancormier/react-native-swipeout My goal is to have the row swiped all the way. Is there a method to increase the button width so that it covers the entire width of th ...

In what way does AngularJS asynchronously navigate through the Angular template made up of HTML and AngularJS Directives?

While diving into the AngularJS book penned by Brad Green and Shyama Sheshadari, I stumbled upon the following insightful passage: The initial startup sequence unfolds as follows: 1. A user triggers a request for your application's first page. ...

In NextJs version 13, you can access parameters from the URL directly within the layout.js file

With the introduction of server components in Next.js 13, accessing parameters from the URL has become seamless. Let's look at an example: app/shop/[tag]/[item]/layout.js /shop/1/2 { tag: '1', item: '2' } When accessing page ...

The dropdown menu is extending beyond its intended position

After solving the issue with my dropdown menu that used to shift all other buttons when hovered over, I stumbled upon a new problem. Now, when the page is scrolled down slightly and a button is hovered over, the dropdown appears in its original position in ...

Retrieving and updating the attribute value for d3.symbolTriangle

Currently, I am utilizing d3.symbolTriangle to create equilateral triangles in my project. I am interested in learning how to access and modify the attribute values. This is a snippet of my code: var body = d3.select("body"); var triangle = d3.symbol() ...

Sending a file stream with specific file name and extension in NodeJS: A comprehensive guide

Currently, I am utilizing nodejs to transmit file streams to express response var fileReadStream = fs.createReadStream(filePath); fileReadStream.pipe(res); However, the issue arises on the front-end where the file is solely downloadable with the "download ...

Using JQuery to implement a date and time picker requires setting the default time based on the server's PHP settings

I have implemented a jQuery UI datetime picker in my project. As JavaScript runs on the client side, it collects date and time information from the user's machine. Below is the code snippet I am currently using: <script> // Function to set ...

Utilizing Selenium with JavaScript to programmatically interact with web elements embedded within iframes

I am currently attempting to access web elements within an iFrame programmatically. I am using the following method to verify this: Check the URL of elements against the base URI If they match, the web element is in the main DOM; if not, it is located in ...

Achieving nested routes without the need for nested templates

My Ember routes are structured like this: App.Router.map(function() { this.resource("subreddit", { path: "/r/:subreddit_id" }, function() { this.resource('link', { path: '/:link_id'} ); }); }); However, ...

Scrape dynamic web data with JSOUP

Having trouble grabbing the price? I cannot seem to get any output for the price and its weight. I've attempted different methods, but nothing is working Document doc = Jsoup.connect("https://www.jakmall.com/tokocamzone/mi-travel-charger-20a-output- ...

Tips for containing bleach spills in Markdown using the ">" quotation tag:To prevent bleach from escaping, utilize the blockquote

My current method of sanitizing user input involves using bleach and Markdown. However, I am facing an issue where the blockquote > symbol is being escaped as & gt; instead of passing it through for rendering with misaka. The documentation mentions ...

No data returned from API call in Next.js and Strapi

Recently, I encountered an issue with my Next.js frontend application that fetches data from a Strapi backend. Despite seeing requests being made in the Strapi developer logs, the retrieved data is empty. Below is a snippet of my Next.js code: import { us ...

Is there a way to resolve the scrolling problem on Google Maps?

When using the Google Maps V3 API, an issue arises where zooming out on the map using the scrollbar also causes the page to scroll along with it. This can be quite frustrating and so far I have not been able to find a way to disable this scrolling behavi ...

Creating movement effects for a line on an HTML5 canvas following a previous animation

I am facing an issue where my straight line starts animating towards the circle right at the beginning of page load. I am struggling with finding the logic to make the line animate in the opposite direction after the first animation is completed (which is ...

Obtaining verified user information through Express using a JWT token

Having recently ventured into Express, I have prior experience with Laravel and PHP. Currently, my concern lies with a database schema structured like this: Users table : created_by updated_by In Laravel, I could easily auto-fill the 'created_by&ap ...

CSS reinitialization for the HTML5 button element

Is there a way to reset the HTML5 button tag so that it behaves consistently across all browsers? Currently experiencing issues with IE9 going haywire when trying to style the button tag. I am aware of using display:block; but what other solutions exist.. ...