简体   繁体   English

如何将fadeInUp(来自animate.css)与导航栏固定顶部一起使用?

[英]How to use fadeInUp(from animate.css) with navbar-fixed-top?

FadeInUp seems to disable the navbar-fixed-top as whenever i use both of them my navbar scrolls away with the page and when i remove fadeInUp everything work's fine. FadeInUp 似乎禁用了 navbar-fixed-top,因为每当我使用它们时,我的导航栏都会随着页面滚动,而当我删除淡入淡出时,一切正常。 I have used fadeInUp propert from animate.css in my MainApp.jsx.我在 MainApp.jsx 中使用了 animate.css 中的fadeInUp 属性。 I want to use both of them, so is there any way to fix the problem.我想同时使用它们,所以有什么办法可以解决这个问题。

MainApp.jsx主应用程序.jsx

import React from "react"
import { render } from "react-dom"
import Headline from "./components/Headline"
import Footer from "./components/Footer"

class MainApp extends React.Component{
    constructor(props) {
        super(props);
        this.state = {
            load : false,
        }
    }

    componentDidMount(){
        this.setState({
            load : true,
        })
    }

    render(){
            return(
                <div className="animated fadeInUp">
                    <Headline>Heres the main page</Headline>
                    <Footer></Footer>
                </div>
            )
    }
}

render(<MainApp/>, document.getElementById('MainApp'))

Headline.jsx Headline.jsx

import React from "react"
import styles from "./css/navbarItems.css"


export default class Headline extends React.Component {

    handleSelect(selectedKey) {
      alert('selected ' + selectedKey);
    }

    render() {
    return (
        <div>
            <div>
                <nav className="navbar navbar-inverse navbar-default navbar-fixed-top">
                  <div className="container-fluid">
                    <div className="navbar-header">
                      <button type="button" className="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
                        <span className="icon-bar"></span>
                        <span className="icon-bar"></span>
                        <span className="icon-bar"></span>                        
                      </button>
                      <a className="navbar-brand" href="#">WebSiteName</a>
                    </div>
                    <div className="collapse navbar-collapse" id="myNavbar">
                      <ul className="nav navbar-nav">
                        <li className="active"><a href="#">Home</a></li>
                        <li className="dropdown">
                          <a className="dropdown-toggle" data-toggle="dropdown" href="#">Page 1 <span className="caret"></span></a>
                          <ul className="dropdown-menu">
                            <li><a href="#">Page 1-1</a></li>
                            <li><a href="#">Page 1-2</a></li>
                            <li><a href="#">Page 1-3</a></li>
                          </ul>
                        </li>
                        <li><a href="#">Page 2</a></li>
                        <li><a href="#">Page 3</a></li>
                      </ul>
                      <ul className="nav navbar-nav navbar-right">
                        <li><a href="#"><span className="glyphicon glyphicon-user"></span> Sign Up</a></li>
                        <li><a href="#"><span className="glyphicon glyphicon-log-in"></span> Login</a></li>
                      </ul>
                    </div>
                  </div>
                </nav>
            </div>
        </div>
    )
  }
}

you're trying to add both position fixed for navigation while relative or absolute at the time of animation that's why it's not working.您试图在动画时添加固定导航位置,而相对或绝对位置,这就是它不起作用的原因。 to animate something in react you can refer this doc guide to use animation in react要在反应中为某些内容设置动画,您可以参考此文档指南以在反应中使用动画

Or you can run some jQuery in componentDidMount and add nav-fixed class after your animations finised.或者您可以在 componentDidMount 中运行一些 jQuery 并在动画完成后添加导航固定类。

Still I will suggest first approach我仍然会建议第一种方法

The issue might be fixable with body { overflow-x: hidden; }该问题可能可以通过body { overflow-x: hidden; } body { overflow-x: hidden; } because animate.css affects floating stuff eg menus or other elements with position: fixed; body { overflow-x: hidden; }因为animate.css影响浮动东西例如菜单或与其它元件position: fixed; . . Give it a try.试一试。

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

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