Troubleshooting the problem of fast rotation and scrolling of text in the middle but slow movement at the end with

Currently, I am utilizing the jquery animate function for animating text while also aiming to rotate the text if a specific degree is passed. In order to achieve this, I have implemented the following code snippet:

var leftCss = "-"+$('#mydiv').width();
var leftAnt = $('#mydiv').parent().width();
$('#mydiv').each(function () {this.xpos =  leftCss; })
           .animate({  xpos: leftAnt}, {
                duration:10000,
                step: function (now) { 
                   var scaleVal =parseInt( now);
                   $(this).css('transform','rotate(0deg) translateX('+scaleVal+'px) translateY('+$('#mydiv').height()+'px)'); 
                },
            },'linear');

https://jsfiddle.net/nufafjjs/1/

Although it begins fast and slows down towards the end, I desire a consistent speed throughout the animation. Any idea what could be causing this inconsistency? Furthermore, when the rotation exceeds 90 degrees, the text disappears from view.

Thank you!

Answer №1

In this scenario, the reason why the default easing swing is applied to the animation is because you are passing animate options as the second parameter in the .animate() function and the third parameter 'linear' doesn't make sense here. To resolve this issue, you need to include easing:'linear' within the second options parameter like so:

function scrollAnimation() {
  $(".item").each(function() {
    this.offsetX = '-' + $('.item').width();
  }).animate({
    offsetX: parseInt($('.container').width())
  }, {
    duration: 10000,
    step: function(now, fx) {
      var moveValue = parseInt(now);
      moveValue += 10;
      $(this).css('transform', 'rotate(0deg) translateX(' + moveValue + 'px) translateY(0px)');
    },
    complete: function() {
      return scrollAnimation();
    },
    easing: 'linear' // specify linear easing here
  });
}
scrollAnimation();
.item {
  position: absolute;
  float: left;
  font-size: 50px;
  background-color: red;
}

.container {
  width: 500px;
  height: 50px;
  border: solid;
  position: absolute;
  overflow: hidden;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container">
  <div class="item">some content here....</div>
</div>

Answer №2

For a sleek and simple solution, utilize CSS animations exclusively. To maintain a consistent speed throughout the animation, make use of animation-timing-function:linear. Adjust the speed of the animation by modifying the value of animation-duration.

.block {
  position: absolute;
  float: left;
  font-size:50px;
  background-color: red;
  animation-name: example;
  animation-duration: 6s;
  animation-timing-function:linear;
  animation-iteration-count: infinite;
  
  //or just a shorthand
  //animation: example 6s linear infinite;
}
  
@keyframes example {
  from {transform:translateX(-500px);}
  to {transform:translateX(500px);}
}
.parent{
  width:500px;
  height: 50px;
  border:solid; 
  position: absolute;
  overflow:hidden
}
<div class="parent">
<div class="block">some content here....</div>

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

Stylish Pop-up Box appears hidden behind a different element

Is there a way to fix the issue of the FancyBox plugin being blocked by some part of the HTML on the page when trying to load a Vimeo movie into a popup? Here is the live link: click here : it's when you click on the slider image underneath the yello ...

Unusual Actions from the Text Field

Please take a look at this link <div id="textarea_wrapper"> <textarea>How and where is my width derived from?</textarea> </div> #textarea_wrapper{ height: 250px; border:thick solid green; } textarea{ background-color: #930; ...

"Escaping from the typeahead feature in Angular-UI Bootstrap results in the input field value becoming

Having some difficulty solving a particular edge case scenario. When I select a value from the dropdown of the typeahead using either the keyboard or mouse, the ng-model in the input field is populated correctly. However, if I type a few letters and then ...

Vue displays error logs within Karma, however, the test failure is not being reflected in the Karma results

Currently, I am in the process of writing unit tests for Vue components within our new project. For testing, I am utilizing Karma with Mocha + Chai, and PhantomJS as the browser. The test command being used is cross-env BABEL_ENV=test karma start client/ ...

Error Encountered: "JSON Post Failure in ASP.net MVC resulting in 500

Whenever I attempt to send a variable to JSON on ASP.net MVC, I encounter the following error: jquery-2.2.3.min.js:4 GET http://localhost:58525/Order/GetAddress/?userid=42&email=asandtsale%40gmail.com 500 (Internal Server Error) This is my controller ...

When using ng-repeat with Angular ui-bootstrap and tabs, the new tab will not be selected if there are no existing tabs present

To showcase the problem I'm facing, please refer to this link: http://codepen.io/pietrofxq/pen/ZLLJdr?editors=1010 Click on "remove tabs" and then on "add tab" The challenge at hand involves using a loop with ng-repeat to display tabs. At times, the ...

Obtaining the blog slug dynamically upon clicking with ReactJS

Currently, I am developing a project using Reactjs and Nextjs. One of the tasks at hand is to obtain the "slug" value after clicking on a blog post. However, at this moment, the value returned is undefined despite trying the following code: <h4 onClic ...

Discover the best practices for utilizing the npm commands.test function

Looking to create a function that can return the output from running npm test. (this function can be called as npm.commands.test(packages, callback) here) Attempted to use it in this way: var npm = require("npm"); npm.load('', function(err, np ...

Customize the appearance of each TreeItem in JavaFX using CSS to assign unique

I am looking for a way to color individual Tree Items in a treeView based on specific conditions. I found a promising answer, but unfortunately, I am struggling to implement it. You can check out the answer here. My main obstacle is understanding how to u ...

Pass user input values to PHP via AJAX and display the outcome on a designated div

I am currently working on a project where I need to send an input value to a PHP script and display the returned value in a div using AJAX. However, I seem to be struggling with getting it to work properly. Any assistance or suggestions would be greatly ap ...

An unforeseen issue arose while trying to update the data in a Chart.js chart within a Vue application

I am currently utilizing Chart.js version 3.5 along with Vue 3. After successfully creating a chart, I attempted to trigger a data change within a Vue method. However, I encountered an issue that displayed the following error message: "Uncaught TypeError: ...

Changing Background Images Based on Screen Size in CSS Media Queries

Hey there, I am currently using two different header images - one for desktop and another for both tablet and mobile devices. I am wondering how I can automatically switch from the desktop header image to the mobile/tablet header image when the screen siz ...

In Vue, reactivity does not extend to nested child objects

I am dealing with JSON data structured like this- items: { id: 1, children: [{ id: 2, parentId: 1, children: [{ id: 3, parentId: 2 }] }] } level-1 children represent parent items that all possess a parent_id of 1 (the roo ...

Working with the React JS Reducer, I am limited to only printing the returned payload and unable to perform any other actions

I've been struggling with this problem non-stop for several days now. Here's my reducer file: import {ADD_TASK, GET_TASKS, GET_TASKS_ERROR, GET_TASKS_SUCCESS} from "./TaskActions"; export const INITIAL_STATE = { tasks: [], isFetching: ...

What is the best way to tile textures in Three.js without causing distortion?

Despite trying various solutions, I am still facing an issue where my textures appear to be stretched or scaled based on the mesh size. In a bid to seek a resolution, here are some key points to note: All textures have dimensions of 64x64 pixels I have p ...

Tips for inserting a property into an array of objects when it matches the specified ID

As someone new to Angular, I am encountering an issue and would appreciate some help. Here is an array of objects I am working with: signals = [{ 'signalID': '123' },{ 'signalID': '233' },{ 'signalID': &apo ...

JavaScript Execution Sequence: Demystifying the Order of Operations

I am struggling to comprehend the order of execution in the following code snippet. It is a portion of a larger script, but it all begins with $( "#select-overlay" ). function findSelectedMap(mapID) { $.getJSON('maps.json', function (json) { ...

Guide to sharing a global object among multiple Vue.js mini apps within the same page

As we embrace the progressive nature of Vue.js, we are gradually transitioning our online shopping experience into a Vue.js-powered Single Page Application (SPA). One step at a time, we implement Vue.js to render specific components such as the mini-cart ...

JavaScript module encounters an uncaught error: Attempting to assign a value to a constant variable

In another module, I defined a variable in the following manner: // module1.js let directory; export { directory }; Now, I am trying to access it in a separate module like so: // module2.js import { directory } from '../js/module1.js'; directo ...

At random intervals, a ReferenceError is triggered stating that Vue is not defined

While working on an application that uses templates rendered by Apache Velocity, I encountered the error "Uncaught ReferenceError: Vue is not defined" when trying to incorporate vue.js components. Oddly enough, this error is not consistent - it occurs most ...