Skip to content
Permalink
5dff89a69d
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
30 lines (22 sloc) 719 Bytes
import React, {useState} from 'react';
const ScrollButton = () =>{
//Controlamos con un Hook si debemos mostrar el botón
const [showScroll, setShowScroll] = useState(false)
const checkScrollTop = () => {
if (!showScroll && window.pageYOffset > 400){
setShowScroll(true)
} else if (showScroll && window.pageYOffset <= 400){
setShowScroll(false)
}
};
const scrollTop = () =>{
window.scrollTo({top: 0, behavior: 'smooth'});
};
window.addEventListener('scroll', checkScrollTop)
return (
<div>
<i className="fa fa-arrow-circle-up fa-3x scrollTop" onClick={scrollTop} style={{display: showScroll ? 'flex' : 'none'}}/>
</div>
);
}
export default ScrollButton;