对于动画问题,使用jQuery和React是否真的是一个坏主意?使用状态的CSS类更好吗?如何使用React向下滚动导航栏?
我有这样的模板与导航栏菜单,但我会与向下滚动条来执行一个jQuery褪色,这是不对的我的模板喜欢或者我怎么可以添加这样的效果
我有我的主模板称为landing.js
import React from 'react';
import NavbarBoots from './Vitae-Plantilla/NavbarBoots';
import NavbarLanding from './Landing-Plantilla/NavbarLanding';
import CabeceraLanding from './Landing-Plantilla/CabeceraLanding';
import CuerpoLanding from './Landing-Plantilla/CuerpoLanding';
import PieLanding from './Landing-Plantilla/PieLanding';
export default class Landing extends React.Component {
componentDidMount() {
var scrollTop = $(window).scrollTop();
$(window).scroll(function(){
if(scrollTop > 100) {
$('#.main_h').fadeOut();
} else {
$('#.main_h').fadeIn();
}
});
}
render() {
return (
<div className="container-landing">
<header id=".main_h"className=".main_h">
<NavbarBoots/>
<div className="cabecera-landing">
<CabeceraLanding title="Cabecera" subtitle="el pais del nunca jamás."/>
</div>
</header>
<div className="body-landing-">
<div className="cuerpo-landing">
<CuerpoLanding title="Acerca de mi."/>
</div>
<div className="pie-landing">
<PieLanding title="pie"/>
</div>
</div>
</div>
);
}; // render
} // Landing
这些是我的页面的样式,但我怎么能让导航栏也停下来。
.container-landing {
.main_h {
background: url(http://www.vqronline.org/sites/vqr.virginia.edu/files/story-images/petrusich_honis_opener_cssp_aur-mw_oct2015_1.jpg) center no-repeat;
position: fixed;
top: 0px;
max-height: 70px;
z-index: 999;
width: 100%;
padding-top: 17px;
background: none;
overflow: hidden;
-webkit-transition: all 0.3s;
transition: all 0.3s;
opacity: 0;
top: -100px;
padding-bottom: 6px;
font-family: "Montserrat", sans-serif;
}
.main_h .sticky{
background-color: rgba(255, 255, 255, 0.93);
opacity: 1;
top: 0px;
border-bottom: 1px solid gainsboro;
}
@media only screen and (max-width: 766px) {
.main_h {
padding-top: 25px;
}
}
一般来说,我会说在可能的情况下使用CSS动画优于jQuery或任何JavaScript衍生的动画方法。原因是由css本身实现的动画可以从优化与GPU的操作的浏览器中受益。通常,使用javascript完成的动画将涉及对DOM进行频繁更改,这将导致频繁的页面重绘,从性能角度来看,以及可能的动画流动流,这是一件坏事。这是我从我自己的个人研究中收集到的。 – Taplar