Adjusting the size of text using a central point

Currently, I am working on creating an animation that involves text resizing based on scrolling direction. The idea is that when scrolling down, the text decreases in size, and when scrolling up, it increases. Additionally, as the user scrolls down, the text should remain fixed in its position. However, I have encountered a problem where zooming in and out causes the text to become unlinked from its intended point. To better illustrate this issue, I have created a GIF which you can view here.

To showcase what is actually happening with the animation, please refer to this example image: Click here.

Here is the code snippet for achieving this effect:

<div class="main__logo">
     <h1 id="logo">
          Fashion
     </h1>
</div>

And here is the corresponding CSS code:

.main__logo {
  font-size: 200px;
  position: fixed;
  margin-top: 0;
}
.main__logo .logo__sticky {
  position: fixed;
  font-size: 24px;
  margin-top: -80px;
}
#logo {
  -webkit-transition: all .4s ease;
  -o-transition: all .4s ease;
  transition: all .4s ease;
}

Lastly, the jQuery script used for controlling the text resizing based on scroll direction:

$(window).scroll(function () {
  if ($(this).scrollTop() > 80) {
    $("#logo").addClass("logo__sticky");
  } else {
    $("#logo").removeClass("logo__sticky");
  }
});

Answer №1

My recommendation is to utilize animate, as it simplifies the process of animating each frame similar to what you see in the video.

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

Condition formulation using dynamic dust JS equality

I'm struggling with a seemingly simple task - dynamically changing the @eq condition. The example provided shows a default render, but what I really need is to allow user input to change it to either "Larry" or "Moe". You can view my code on jsfiddle ...

How can I use CSS and jQuery to modify the background color?

I stumbled upon this page and was impressed by the continuous color changes. I looked through the source code but couldn't find the script responsible for the color changes. Can anyone direct me towards the right solution? What script was used to crea ...

Re-executing PHP script using AJAX on the existing webpage

I am facing a rather intricate issue. Currently, I am in the process of constructing a page that searches tags in a MySQL table and displays results without any reloading or redirection. The tags are user-input and managed using JavaScript. Let me outline ...

elements on the page that automatically update using AJAX

On my webpage, there is a news slider that displays items one by one. The page automatically refreshes to show new items. I am working on using ajax and a jquery timer to update the page whenever a new item is added. I'm trying to use AJAX to retriev ...

What are the steps for implementing a two-column layout in reveal.js?

When creating my slides using reveal.js, I write them in Markdown code. I am now looking to present my content (text, bulleted lists, or images) in a traditional two-column text layout. While I am open to a more complex initial setup, I want to ensure that ...

Issues with CSS not being applied when the page content exceeds the viewport

<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width,initial-scale=1"> <title>Unique Title</title> <style> #div1 { posit ...

The initialization of the view keeps happening repeatedly

Currently, I'm in the process of developing a dashboard that bears some resemblance to this one Admin Dashboard Theme In my project, I am incorporating a fixed Right Side Sidebar similar to the one shown in this screenshot https://i.sstatic.net/7KdMY ...

Ways to reduce the width of an input field: Utilizing Bootstrap v5 or employing CSS techniques

I am struggling to find a way to adjust the width of the input window. It seems like there is no specific code that controls the width of the input window. The code snippet below is extracted from the Bootstrap v5 documentation, specifically focusing on th ...

Craft a search bar inspired by Google's iconic design using CSS styling

I need to recreate a custom input styled like the Google Material Theme design. This is the desired outcome: https://i.stack.imgur.com/QU5dp.png While I am aware that frameworks/libraries can achieve this, it is part of my assignment to create it from s ...

I am looking to update a WordPress site every 10 seconds to keep it current

Currently, I am working on a plugin and my goal is to automatically refresh the widget every 10 seconds. Can someone guide me on how to achieve this? I need to figure out a way to call the widget function at regular intervals in order to refresh the conte ...

jQuery file uploader only transmitting a single chunk

Currently, I am integrating the jQuery file uploader into my Django application. I am encountering an issue where Django is only receiving one chunk of my large file. Initially, I suspected a problem with my UploadFileHandler; however, upon logging the ch ...

Apologies, but there was an issue with the pandoc document conversion process, resulting in error 103

I encountered an error message while trying to convert my rmd file to html. Can someone assist me with this issue? "C:/Program Files/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS linearRegression-1-.utf8.md --to html4 --from markdown+autolink_bare_uri ...

How can I eliminate margin and padding from html and body elements in a Vue application?

I have a project that was created using the command vue init webpack my-project. Here is my main.js file: import Vue from 'vue' import App from './App.vue' new Vue({ el: '#app', render: h => h(App) }) and my App.vue ...

The issue of the JQuery div failing to center itself persists even after refreshing the page

I have implemented a script to centrally align the main content div within the viewing area. It works perfectly on page load or resize, but upon page refresh, the content div shifts to the left side of the page. You can see the issue here when pressing re ...

Is it possible to manipulate an Angular #variableName in order to retrieve an ElementRef for an HTML element?

Suppose I have a scenario where I create a button like this: <button #myButton>My Button</button> ...and then use ViewChild in the following way: @ViewChild('myButton', { static: true }) createButton: ElementRef; In this case, creat ...

Maintain the full height of the side bar

My CSS skills aren't the best, so I'm struggling to keep my sidebar at full height even when it doesn't have enough content. Here's my current CSS: #wrapper { display: flex; flex-wrap: wrap; background-color: yellow; } #wrapper .sideBa ...

Embed a video within an image while ensuring it remains responsive on all devices

I have a picture that resembles something like this one My goal is to embed a video into it while maintaining its aspect ratio when the screen size is reduced. The responsive design should only affect the width since the image will be displayed in portrai ...

display the text content of the chosen option on various div elements

I created a subscription form that includes a category dropdown select field. The selected option's text value needs to appear 4 times within the form. It's all part of a single form. <select name="catid" onchange="copy()" id="catid" class="i ...

Guide to creating a PHP loop in the footer of a Magento website

Hey Developers! I have been using the following commands in footer.phtml to retrieve all my cms/blocks in the Magento's footer. <?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('home')->toHtml() ...

Options for searching a grid in jqGrid

On my screen, I have implemented a jqgrid that displays around 3500 records after a search. By using paging, only a maximum of 45 records are visible to the user at any given time. I am looking to add a feature that allows users to print all 3500 records i ...