简体   繁体   English

在React中滚动时,如何使导航栏突出显示?

[英]How do I make my navbar highlight as I scroll in React?

As I scroll to projects, about, contact etc.. i'd like my navbar element for that section to hightlight, lets just say a background of blue. 当我滚动到项目,关于,联系等时。我希望该部分的导航栏元素突出显示,让我说一个蓝色背景。 How can I do this with React? 我该如何使用React做到这一点? i've never done anything like this before. 我以前从未做过这样的事情。

import React from 'react';


const Navbar =()=>
    <div className='navbar'>
        <a href="#home">Home</a>
        <a href="#about">About</a>
        <a href="#projects">Projects</a>
        <a href="#contact" >Contact</a>
    </div>

export default Navbar

this is my navbar I want to highlight 这是我要强调的导航栏

I looked up a ton of of stuff for on scroll with react, none of them where able to help me. 我翻阅了一大堆东西,使它们反应迅速,但没有一个能够帮助我。

thanks for any help 谢谢你的帮助

You can do it using basic CSS 您可以使用基本CSS

a:hover {
  background-color: "YourValue";
  color: "YourValue";
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM