这个功能很好.它将主体滚动到所需容器的偏移量
function scrolear(destino){
var stop = $(destino).offset().top;
var delay = 1000;
$('body').animate({scrollTop: stop}, delay);
return false;
}
Run Code Online (Sandbox Code Playgroud)
但不是在Firefox中.为什么?
-编辑-
要在接受的答案中处理de double触发器,我建议在动画之前停止元素:
$('body,html').stop(true,true).animate({scrollTop: stop}, delay);
Run Code Online (Sandbox Code Playgroud) tl; dr 向下滚动以获取对我有用的解决方案!
如何在反应中在固定导航栏上实现上下滑动?
使用 refs 或使用 componentDidMount 生命周期钩子的更好方法是什么?
hideNav = (navbar) => {
const hide = () => {
let lastScrollTop = 0;
const currentScrollTop = navbar.scrollTop;
// scroll down
if (currentScrollTop > lastScrollTop) {
navbar.classList.add('hidden');
} else {
// scroll up
navbar.classList.remove('hidden');
}
lastScrollTop = currentScrollTop;
};
window.addEventListener('scroll', hide);
};
Run Code Online (Sandbox Code Playgroud)
...在渲染方法中进一步:
render() {
return <Navbar ref={this.hideNav} />
Run Code Online (Sandbox Code Playgroud)
更新:
解决方案:
class Navbar extends React.Component {
state = {
auth: false,
slide: 0, // How much should the Navbar slide …Run Code Online (Sandbox Code Playgroud) 我想为网站创建一个粘性标题栏,就像本网站上的粘性标题(http://www.fizzysoftware.com/)一样,如果有的话可以帮我解决编码或任何帮助我创建相同.你的回复对我很有帮助.