ReactJS Typewriting animation

One of the dream idea to build typewriting in ReactJS. The code seems to be working, still there are something looks not that great in the code 😔 Looking for better solution (best practice) in the function like animationManager()

Demo: https://codesandbox.io/s/qk4591q1kw

index.js

import React from "react"; import ReactDOM from "react-dom"; import Typewriter from "./Typewriter";  import "./styles.css";  const words = [   "Twinkle twinkle little star",   "How I wonder what you are.",   "Up above the world so high",   "Like a diamond in the sky" ];  function App() {   return (     <div className="App">       <h1>Hello CodeSandbox</h1>       <h2>Start editing to see some magic happen!</h2>       <Typewriter data={words} />     </div>   ); }  const rootElement = document.getElementById("root"); ReactDOM.render(<App />, rootElement); 

Typewriter.js

import React, { Component } from "react"; import PropTypes from "prop-types"; import styled, { keyframes } from "styled-components"; let lastTime = performance.now();  const rotate = keyframes`   0% {     border-right: 2px solid tomato;   }   50% {     border-right: 2px solid transparent;   }   100% {     border-right: 2px solid tomato;   } `; const Rotate = styled.span`   color: tomato;   animation: $  {rotate} 0.7s linear infinite; `;  class Typewriter extends Component {   state = {     output: ""   };   index = 0;   rafRef = null;   timeoutRef = null;    static defaultProps = {     typingSpeed: 50,     // it needs to implement in delete function     deletingSpeed: 32,     pauseBeforeRestarting: 200,     pauseBeforeDeleting: 1500,     data: [],     style: {},     className: null   };    componentDidMount() {     this.animationManager();   }    componentWillUnmount() {     // cleanup     if (this.timeoutRef) {       clearTimeout(this.timeoutRef);     }     if (this.rafRef) {       cancelAnimationFrame(this.rafRef);     }   }    animationManager = () => {     this.rafRef = requestAnimationFrame(time => {       const typingData = this.props.data;       this.typeEffect(time, typingData[this.index], () => {         this.timeoutRef = setTimeout(() => {           this.rafRef = requestAnimationFrame(time => {             this.deleteEffect(time, () => {               this.timeoutRef = setTimeout(() => {                 this.index =                   this.index === typingData.length - 1 ? 0 : this.index + 1;                 this.animationManager();               }, this.props.pauseBeforeRestarting);             });           });         }, this.props.pauseBeforeDeleting);       });     });   };    typeEffect = (time, text, callback) => {     if (time - lastTime < this.props.typingSpeed) {       this.rafRef = requestAnimationFrame(time => {         this.typeEffect(time, text, callback);       });       return;     }     lastTime = time;     this.setState({       output: text.substr(0, this.state.output.length + 1)     });     if (this.state.output.length < text.length) {       this.rafRef = requestAnimationFrame(time => {         this.typeEffect(time, text, callback);       });     } else {       return callback();     }   };    deleteEffect = (time, callback) => {     if (time - lastTime < this.props.typingSpeed) {       this.rafRef = requestAnimationFrame(time => {         this.deleteEffect(time, callback);       });       return;     }     lastTime = time;     this.setState({       output: this.state.output.substr(0, this.state.output.length - 1)     });     if (this.state.output.length !== 0) {       this.rafRef = requestAnimationFrame(time => {         this.deleteEffect(time, callback);       });     } else {       return callback();     }   };    render() {     return (       <Rotate className={this.props.className} style={this.props.style}>         {this.state.output}       </Rotate>     );   } }  Typewriter.propTypes = {   typingSpeed: PropTypes.numnber,   deletingSpeed: PropTypes.numnber,   pauseBeforeRestarting: PropTypes.numnber,   pauseBeforeDeleting: PropTypes.numnber,   data: PropTypes.array,   style: PropTypes.object,   className: PropTypes.string };  export default Typewriter; 

Whats wrong with this animation? css/javascript

When i have this code the animation works, but the image is in the wrong position:

     #myAnimationUp {       background-image: url("images/ships/ship<?php echo $  _SESSION['getshiptype']; ?>up.png");       background-size:     cover;                             background-repeat:   no-repeat;       height:55px;        position:absolute;        width:30px;       bottom:1px;        right: 30px;     } 
Code (markup):

So i imagined, pulling the image down with css would do the job since bottom…

Whats wrong with this animation? css/javascript

jQuery Slideshow with animation callback

I have developed a slideshow using jQuery that will pre-loade the next slide, hold the last one, and make the current slide active which adds a class with a delay.

I predict there could be unnecessary duplication within the next and previous buttons. Are there improvements that can be made to the code, and if so, what would these be?

$  (document).ready(function(){      $  ('.slide:eq(-1)').addClass('last');   $  ('.slide:first').addClass('active').delay(1250).queue(function(){     $  (this).addClass('show-text');   });   $  ('.slide:eq(1)').addClass('next');    });  // Previous Slide function prevSlide() {      // Variables   var $  prevActive = $  ('.slide.active');   var $  prevSlide = $  ('.slide').eq(($  prevActive.index() - 1) % $  ('.slide').length);   var $  afterPrevSlide = $  ('.slide').eq(($  prevActive.index() - 2) % $  ('.slide').length);      // Remove previous classes   $  prevActive.dequeue();   $  ('.slide').removeClass('last active show-text next');      // Add the new classes   $  prevActive.addClass('next');   $  prevSlide.addClass('active').delay(1250).queue(function(){     $  (this).addClass('show-text');   });   $  afterPrevSlide.addClass('last');    }  // Next Slide function nextSlide() {      // Variables   var $  activeSlide = $  ('.slide.active');   var $  nextSlide = $  ('.slide').eq(($  activeSlide.index() + 1) % $  ('.slide').length);   var $  slideAfterNext = $  ('.slide').eq(($  activeSlide.index() + 2) % $  ('.slide').length);      // Remove the previous classes   $  activeSlide.dequeue();   $  ('.slide').removeClass('last active show-text next');      // Add the new classes   $  activeSlide.addClass('last');   $  nextSlide.addClass('active').delay(1250).queue(function(){     $  (this).addClass('show-text');   });   $  slideAfterNext.addClass('next');  }  $  ('#prev').click(function(){      prevSlide();    });    $  ('#next').click(function(){      nextSlide();    });
body {   font-size: 16px;   font-family: 'Heebo', sans-serif;   text-transform: uppercase;   font-weight: 900; }  /* Slides */ .slide-wrapper {   position: absolute;   top: 0;   left: 0;   bottom: 0;   right: 0;   display: flex;   overflow: hidden; }  .slide {   position: absolute;   display: flex;   justify-content: center;   align-items: center;   height: 100vh;   width: 70%;   left: 140%;   z-index: 0;   transition: 1.25s;   box-shadow: -10px 0px 21px -5px rgba(0,0,0,0.5); }  .slide h2 {   display: none;   color: #fff;   text-shadow: 0px 0px 8px rgba(0,0,0,0.5);   letter-spacing: -2px;   font-size: 3rem; }  .slide.active.show-text h2 {   display: block;   animation: reveal-text 1.5s forwards; }  @keyframes reveal-text {   0%   { opacity: 0; }   100% { opacity: 1; } }  #slide1 {   background: linear-gradient(to right, #93EDC7, #1CD8D2); }  #slide2 {   background: linear-gradient(to right, #4389A2, #5C258D); }  #slide3 {   background: linear-gradient(to right, #8E54E9, #4776E6); }  #slide4 {   background: linear-gradient(to right, #F45C43, #EB3349); }  .slide.last {   left: 0;   z-index: 0; }  .slide.active {   left: 0;   z-index: 1; }  .slide.next {   left: 70%;   z-index: 2; }  /* Buttons */ .button-wrapper {   display: flex;   z-index: 10;   width: 100%;   justify-content: space-between;   align-items: center; }  .button {   background-color: rgba(0,0,0,0.45);   color: #ddd;   height: 40px;   border: none;   font-weight: bold;   padding: 10px 20px;   transition: 0.3s; }  .button:hover {   cursor: pointer;   background: rgba(0,0,0,0.85);   color: #fff; }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div class="slide-wrapper">   <div id="slide1" class="slide">     <h2>Slide One.</h2>   </div>   <div id="slide2" class="slide">     <h2>Slide Two.</h2>   </div>   <div id="slide3" class="slide">     <h2>Slide Three.</h2>   </div>   <div id="slide4" class="slide">     <h2>Slide Four.</h2>   </div>   <div class="button-wrapper">     <button id="prev" class="button">Prev.</button>     <button id="next" class="button">Next.</button>   </div> </div>

How can I implement animation in my flatlist?

I am using Flatlist in my rn project and when I push new data into my flatlist, my item 1 will automatically move from position A to position B. But my question is I don’t want it to just change the position, I want to use animation to move my item(from position A to position B). How can I implement that? Thank you!

Please check the demo picture and video from the link down below: https://photos.app.goo.gl/WypswNyA38A2EAPQA https://photos.app.goo.gl/Ev1RYMduDj7mxrHn7

2D falling snow animation

I was hoping that someone could review this code.

My main concern is that the contents of main() are difficult to read. I thought about extracting some segments of code into functions (to aid comprehension) but it felt unnecessary because these segments are not completely repeated.

#include <SFML/Graphics.hpp> #include <random>  // Maps input in the range [0..1] to an output in the range [0..1]. // Represents the piecewise function: // y(x) = 2*x^2             when x < 0.5 //      = -2*x^2 + 4*t - 1  when x >= 0.5 float easeInOutQuad(float normalisedTime) {   auto & t = normalisedTime;   return t < 0.5 ? 2*t*t : 2*t*(2 - t) - 1; }  struct Tween {   float begin;   float change;   float time{0};   float duration;   float current() const   {     return begin + change*easeInOutQuad(time/duration);   } };  int main() {   sf::RenderWindow window{sf::VideoMode{500, 500}, "Snow"};   auto const inverseFramerate = 1.f/60;   window.setFramerateLimit(static_cast<unsigned>(1/inverseFramerate));   auto const numberOfSnowflakes = 200;   Tween tweens[numberOfSnowflakes];   float yPositions[numberOfSnowflakes];   auto generator = std::mt19937{};   // Returns a normally distributed random number.   auto randomChangeInX = [&generator]()   {     static auto distribution = std::normal_distribution<float>{0.f, 10.f};     return distribution(generator);   };   // Returns a uniformly distributed random number in the range [min..max).   auto randomBetween = [&generator](float min, float max)   {     return std::generate_canonical<float, 10>(generator)*(max - min) + min;   };   for (auto i = 0; i < numberOfSnowflakes; ++i)   {                  tweens[i].begin = randomBetween(0, window.getSize().x);     tweens[i].change = randomChangeInX();     tweens[i].duration = randomBetween(1, 5);      yPositions[i] = randomBetween(-20, window.getSize().y);   }   auto const defaultRadius = 5.f;   auto circle = sf::CircleShape{};   while (window.isOpen())   {     auto event = sf::Event{};     while (window.pollEvent(event))     {       if (event.type == sf::Event::Closed)       {         window.close();       }     }     for (auto i = 0; i < numberOfSnowflakes; ++i)     {       tweens[i].time += inverseFramerate;       if (tweens[i].time > tweens[i].duration)       {         tweens[i].begin += tweens[i].change;         tweens[i].change = randomChangeInX();         tweens[i].time = 0;       }        yPositions[i] += 1/tweens[i].duration;       if (yPositions[i] > window.getSize().y)       {         yPositions[i] = -defaultRadius*2;         tweens[i].begin = randomBetween(0, window.getSize().x);         tweens[i].change = randomChangeInX();         tweens[i].time = 0;       }     }     window.clear();     for (auto i = 0; i < numberOfSnowflakes; ++i)     {       circle.setPosition(tweens[i].current(), yPositions[i]);       circle.setRadius(defaultRadius/tweens[i].duration);       window.draw(circle);           }     window.display();   } } 

Whiteboard Animation Video designed especially for you for $40

I will create a whiteboard animation video for your business or project. Up to full HD Background Music 2 – 3 minutes Including voice over and script 24 hour delivery https://www.youtube.com/watch?v=unHT9sdzhbs&t Have a look at the video above to get an example of what the video will look like and how I can custom make it for you

by: DubbelGee
Created: —
Category: Video
Viewed: 114


Stop moving an js animation

Hi all, so im new to javascript.
Im currently creating a browser game and found a little bit of code on how to make an animation. E.g Image or another div.
So the problem here is that i need it to move within the MyContainer of 100 by 100 pixels. It just goes to the right bottom corner of my screen. How to stop the animation after 100 pixels for example?

Here is my code:

 //css #myContainer {   width: 100px;   height: 100px;   position: relative; } #myAnimation {   background-image:...
Code (markup):

Stop moving an js animation

No offline battery animation android oreo

Currently i am facing issue in no offline battery animation, which is charging animation while phone is turned off when charging. i already tried to put charging icon in the folder, but it wont work

Currently i am using OnePlus X (E1003) Android Open Source illusion Project (AOSiP) 8.1.0

PS: I am not asking at the forum because the dev isn’t respond anymore, and so far i tried ways on the internet (delete data and cache media, which resulting problem in gallery related, delete cache in TWRP)