So I have this code here below. I just want to move this sticky button to the right or to any different different position on screen when I do scroll down. I already ask some friend and you cannot use onScroll
or something similar on React, you have to create document-on-scroll-something
I believe, I am stuck, and I need help. Again, here's my code below.
App.js
import React from "react";
import "./styles.css";
export default function App() {
return (
<div className="App">
<ScrollTest />
</div>
);
}
class ScrollTest extends React.Component {
render() {
return (
<div id="myScroll">
<button className="myButton">Click Me</button>
<h3>Title</h3>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
minim veniam, quis nostrud exercitation ullamco laboris nisi ut
aliquip ex ea commodo consequat. Duis aute irure dolor in
reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
culpa qui officia deserunt mollit anim id est laborum.
</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
minim veniam, quis nostrud exercitation ullamco laboris nisi ut
aliquip ex ea commodo consequat. Duis aute irure dolor in
reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
culpa qui officia deserunt mollit anim id est laborum.
</p>
</div>
);
}
}
style.css
.App {
font-family: sans-serif;
text-align: justify;
}
#myScroll .myButton {
position: sticky;
top: 0;
}
index.js
import React from "react";
import ReactDOM from "react-dom";
import App from "./App";
const rootElement = document.getElementById("root");
ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
rootElement
);
Or you can visit my live code here
Thanks a lot
EDIT: typo, supposed onScroll
not onScreen