1. 添加动态效果组件

  yarn add react-transition-group

2. 修改 src/common/header/index.js

import React, {Component} from 'react';

import {CSSTransition} from 'react-transition-group';

import {

HeaderWrapper,

Logo,

Nav,

NavItem,

SearchWrapper,

NavSearch,

Addtion,

Button

} from './style';

class Header extends Component{

constructor(props){

super(props);

this.state = {

focused : false

}

this.searchFocus = this.searchFocus.bind(this);

this.searchBlur = this.searchBlur.bind(this);

}

searchFocus(){

this.setState({

focused : true

})

}

searchBlur(){

this.setState({

focused : false

})

}

render(){

return (

<HeaderWrapper>

<Logo />

<Nav>

<NavItem className="left active">首页</NavItem>

<NavItem className="left">下载</NavItem>

<NavItem className="right">登陆</NavItem>

<NavItem className="right">

<span className="iconfont">&#xe601;</span>

</NavItem>

<SearchWrapper>

<CSSTransition

in={this.state.focused}

timeout={200}

classNames='slide'

>

<NavSearch

className={this.state.focused? 'focused' : ''}

onFocus={this.searchFocus}

onBlur={this.searchBlur}

></NavSearch>

</CSSTransition>

<span className={this.state.focused? 'focused iconfont' : 'iconfont'}>&#xe60b;</span>

</SearchWrapper>

</Nav>

<Addtion>

<Button className='writting'>

<span className="iconfont">&#xe703;</span>

写文章

</Button>

<Button className='reg'>注册</Button>

</Addtion>

</HeaderWrapper>

);

}

}

export default Header;

3. 修改 src/common/header/style.js

引入 slide-enter  ,   slide-enter-active , slide-exit , slide-exit-active

import styled from 'styled-components';

import LogoPic from '../../statics/logo.png';

export const HeaderWrapper = styled.div`

postition: relate;

height:56px;

border-bottom:1px solid #f0f0f0;

`;

export const Logo = styled.a.attrs({

href : '/'

})`

position: absolute;

left : 0;

top : 0;

display: block;

height:56px;

width:100px;

background: url(${LogoPic}) no-repeat;

background-size: contain;

`;

export const Nav = styled.div`

width:960px;

box-size: box-size;

padding-right: 70px;

height: 56px;

margin-left: 100px;

`

export const NavItem = styled.div`

&.left {

float: left;

}

&.right {

float: right;

color: #969696;

}

&.active {

color: #ea6f5a;

}

line-height: 56px;

front-size: 15px;

padding-left: 6px;

padding-right: 12px;

color: #333;

`;

export const SearchWrapper = styled.div`

float: left;

position: relative;

.iconfont {

position: absolute;

right: 5px;

bottom: 5px;

width: 30px;

line-height:30px;

border-radius : 15px;

text-align:center;

&.focused{

background : #777;

color : #fff;

}

}

`;

export const NavSearch = styled.input.attrs({

placeholder : '搜索'

})`

width : 160px;

height : 38px;

border: none;

outline : none;

padding : 0 35px 0 20px;

box-size: box-size;

margin-top: 9px;

margin-left: 20px;

border-radius : 19px;

background: #eee;

font-size: 14px;

&::placeholder{

color: #999;

}

&.focused{

width: 200px;

}

&.slide-enter {

width: 160px;

transition: all .2s ease-out;

}

&.slide-enter-active {

width: 200px;

}

&.slide-exit {

width: 200px;

transition: all .2s ease-out;

}

&.slide-exit-active {

width: 160px;

}

`;

export const Addtion = styled.div`

position:absolute;

right: 0;

top: 0;

height: 65px;

`;

export const Button = styled.div`

float:right;

line-height:38px;

margin-top:9px;

margin-right: 20px;

border-radius: 19px;

border : 1px solid rgba(236,97,73,.7);

color : #fff;

padding : 0 20px;

&.reg{

color:#ea6f5a;

}

&.writting{

background:#ea6f5a;

}

`;

3 react 简书 添加 头部搜索动态效果的更多相关文章

  1. react 简书开发笔记

    详见文章<React简书开发实战课程笔记>

  2. 2. react 简书 头部(header) 图标添加

    1. 访问 iconfont 并注册 登陆 2. 进入 iconfont 头部 图标管理->我的项目 3. 点击右边的文件夹 + 号 图标 创建我的项目 输入项目名称即可 4.在 搜索框 搜索 ...

  3. 2. react 简书 头部 (header) 样式编写

    1. 在 src 下 创建 common 文件下 创建 header 文件夹下 创建 index.js #src/common/header/index.js import React, {Compo ...

  4. React 简书

    create-react-app   jianshu yarn add styled-components -D       利用js写css样式  样式会更高效 https://github.com ...

  5. 4 react 简书 引入 redux 的 combineReducers 对 redux 数据进行管理

    1. src 下的 common 下的 header 创建 store 文件夹 下创建 reducer.js # src/common/header/store/reducer.js const st ...

  6. react简书

    开发项目之前的准备 https://www.chromefor.com/  登录此网站 下载相关crx react插件 不然要FQ 下载 React Developer Tools 谷歌插件下载 Re ...

  7. react简书笔记一 环境, git 和 项目 关联

    1.. 建立git项目  ( 码云, github 都可以 ), 具体步骤: https://www.cnblogs.com/andy-lehhaxm/p/10720717.html 1.1  git ...

  8. 1. react 简书 项目初始化

    1. 创建 react 项目 npx create-react-app my-app 2. src 目录下删除 除了 index.js index.css app.js 的文件 3. 引入 style ...

  9. vue添加滚动事件,解决简书Carol_笑一笑方案中vue移除滚动事件失效的问题

    在写项目的时候,遇到了需要添加滚动事件的问题,在简书Carol_笑一笑这里找到了解决方案.代码如下 <script> export default { name:"vue-scr ...

随机推荐

  1. 「CF600E」Lomsat gelral

    传送门 Luogu 解题思路 线段树合并板子题(也可以 dsu on the tree) 好像没什么好讲的,就是要注意开 long long . 细节注意事项 咕咕咕 参考代码 #include &l ...

  2. 阿里云服务器win2003下iis整合tomcat共享80端口

    阿里云服务器win2003下iis整合tomcat共享80端口 很多机器都用tomcat跟IIS部署不同网站.最近买了阿里云的服务器.于是也想玩一下.网上百度了很多方法.但是都有缺陷说的不是很清楚.通 ...

  3. JSONObject.fromObject() 转string时,实体里面的时间错乱的问题

    在把要入库的数据实体转成JSON字符串发给kafka的时候,出现了问题,转换完以后,就变成这样子的了,真的是第一次见到这种,真的是长见识了 然后百度了一下:https://www.cnblogs.co ...

  4. 2017 青岛现场赛 I The Squared Mosquito Coil

    Lusrica designs a mosquito coil in a board with n × n grids. The mosquito coil is a series of consec ...

  5. Ternsorflow 学习:006-MNIST进阶 深入MNIST

    前言 这篇文章适合实践过MNIST入门的人学习观看.没有看过MNIST基础的人请移步这里 深入MNIST TensorFlow是一个非常强大的用来做大规模数值计算的库.其所擅长的任务之一就是实现以及训 ...

  6. mac下添加环境变量

    1.环境变量相关文件说明: a. /etc/profile b. /etc/paths c. ~/.bash_profile d. ~/.bash_login e. ~/.profile f. ~/. ...

  7. H5易企秀

    周末被领导叫回来加班,说要做一个易企秀一样的页面,然后就有这篇笔记 原计划用几百个计时器去执行,后面放弃了,太难改了,还是选择了animate.css插件,这是一个纯css的插件,只需要引入css就行 ...

  8. System.Data.SqlClient.SqlException: 'Incorrect syntax near 'OFFSET'.

    https://www.nopcommerce.com/boards/t/54586/410-not-running-on-local-system.aspx#209684 Hello, I was ...

  9. JuJu团队12月3号工作汇报

    JuJu团队12月3号工作汇报 JuJu   Scrum 团队成员 今日工作 剩余任务 困难 于达 修改batch里给sentence加padding的方法 继续调试 无 婷婷 给crossentro ...

  10. 【LeetCode】226. 翻转二叉树

    题目 翻转一棵二叉树. 示例: 输入: 4 / \ 2 7 / \ / \ 1 3 6 9 输出: 4 / \ 7 2 / \ / \ 9 6 3 1 本题同[剑指Offer]面试题27. 二叉树的镜 ...