javascript - React/JS - onMouseOver 更改字体

标签 javascript reactjs mouseover

我不熟悉代码、语言或术语,但我希望以适当的方式将 Hover/mouseEnter 上的 fontStyle1 从 scss 更改为 fontStyle2!

提前致谢。

scss:

fontStyle1{font-family: $Scope-One;}
fontStyle2{font-family: $Rouge-Script;}

js:

function NavBar() {
    return (
    <div>
    <Navbar className="colorNav" collapseOnSelect expand="lg" variant="dark">
    <Navbar.Brand id="fontStyle1" href="/">
      <img
        alt="BrandName"
        src= {Logo}
        width="30"
        height="30"
        className="d-inline-block align-top"
      />{' '}
      BrandName
    </Navbar.Brand>
    <Navbar.Toggle aria-controls="responsive-navbar-nav"/>
  <Navbar.Collapse id="responsive-navbar-nav">
    <Nav className="mr-auto"/>
    <ul className="navbar-nav">
            <li><Link to={'/'} className="nav-link"> About </Link></li>
            <li><Link to={'/bookmark'} className="nav-link">Bookmark</Link></li>
    </ul>
  </Navbar.Collapse>
    </Navbar>
    </div>
    );
    }

    export default NavBar;

最佳答案

尝试使用 SCSS 设置悬停样式:

.logo {
  font-family: $Scope-One;

  &:hover {
    font-family: $Rouge-Script;
  }
}

JS(已更改id):

...
<Navbar.Brand id="navlogo" className="logo" href="/">
...

关于javascript - React/JS - onMouseOver 更改字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59967407/

相关文章:

javascript - 如何在 react 中水平对齐2行?

jquery - 使用 jQuery 改变不透明度

javascript - 如何通过了解身份验证状态访问 protected 路由/禁用 Auth Guard

c# - 在计时器上刷新 Gridview 但保持扩展 div 的状态

javascript - 循环 HTMLCollection 时包装元素会导致问题

javascript - React JS 和 sublime text 不兼容

javascript - 如何在网页上检索时从数据库中追加数据?

reactjs - React-Redux : mapDispatchToProps methods not found

css - 图像鼠标悬停上的文字?

jquery - 仅为其所属的图像切换 .wp-caption-text