Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i move a text right of the screen and back to left of screen

Tags:

css

reactjs

I want to make a game. How can I make a h1 tag move left to right in reactjs ?

import React from 'react';

const Hello = (props) => (<React.StrictMode><h1 className = "App">Hello {props.name}</h1></React.StrictMode>);

export default Hello;
like image 261
Umut Arpat Avatar asked Jan 18 '26 19:01

Umut Arpat


1 Answers

I created this solution: codepen:

const App = () => {
    return (
      <div className="wrapper">
        <p className="marquee">Hello, world!</p>
      </div>
    );
}

  ReactDOM.render(
    <App />,
    document.getElementById('root')
  );

css file:

body{ 
    overflow: hidden;
}
p{
    position: absolute;
    white-space: nowrap;
    animation: floatText 5s infinite alternate ease-in-out;
}

@-webkit-keyframes floatText{
  from {
    left: 00%;
  }

  to {
    /* left: auto; */
    left: 100%;
  }
}
like image 121
Ibraheem Ahmed Avatar answered Jan 21 '26 09:01

Ibraheem Ahmed



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!