Answer the question
In order to leave comments, you need to log in
How to write such JS code in React?
There is a button that lowers the page to certain coordinates:
<div class="container">
<div class="down">
<div class="down-text">DOWN
<button onclick="topFunction2Section()" class="myBtn2" title="Down">❯</button>
</div>
</div>
</div>
<style>
.container{
background: yellow;
height: 3000px;
width: 100%;
}
</style>
<script>
function topFunction2Section() {
document.body.scrollTop = 940;
document.documentElement.scrollTop = 940;
}
</script>
Answer the question
In order to leave comments, you need to log in
const ScrollButton = props => {
const onClick = () => window.scrollTo({
top: props.scrollTo,
behavior: 'smooth',
});
return (
<div className="down" style={{ top: `${props.top}px` }}>
Scroll to {props.scrollTo}
<button onClick={onClick}>❯</button>
</div>
);
};
const App = () => (
<div className="container">
<ScrollButton scrollTo={500} top={50} />
<ScrollButton scrollTo={1000} top={100} />
<ScrollButton scrollTo={2000} top={200} />
</div>
);
.down {
position: fixed;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question